2014-10-29 74 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 2014-10-29 19:54:43

回答

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

DomDocument

是Google的第一個結果。