2014-10-29 31 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的第一个结果。