2014-10-29 1 views
-2

I want to get all img tags from drupal site and then add a tag between.모든 img 태그를 가져와 <a href=""/> between

I try the below:

$html_img = new simple_html_dom(); 
    // Load HTML from a string. 
$html_img->load($node->body[LANGUAGE_NONE][0]['value']); 
    // Remove all plain text fragments. 
    foreach ($html_img->find('img') as $e) { 
    $e = "<a href='$node_url'>$e</a>"; 
    } 

With above code I take all img tags from drupal but the $e = "<a href='$node_url'>$e</a>"; doesn't put a link to img tags.

+1

문제가있는 코드를 게시하여 문제를 해결할 수 있습니까? – Crackertastic

답변

2
$dom = new DOMDocument; 
$dom->loadXML($xml); 
$images = $dom->getElementsByTagName('img'); 
foreach ($images as $img) { 
    echo "<a href='#'>$img</a>"; 
} 

DomDocument을 추가하십시오.

Google에서 첫 번째 결과입니다.