我想从drupal站点获取所有img
标签,然后在它们之间添加a tag
。
我尝试以下方法:
$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>";
}
在上面的代码中,我从drupal获得了所有的img标记,但$e = "<a href='$node_url'>$e</a>";
没有链接到img标记。
$dom = new DOMDocument;
$dom->loadXML($xml);
$images = $dom->getElementsByTagName('img');
foreach ($images as $img) {
echo "<a href='#'>$img</a>";
}
DomDocument。
是谷歌的第一个结果。