[英]PHP: Simple HTML DOM Parser - how to get the element which has certain tag name?
In PHP I'm using the Simple HTML DOM Parser class. 在PHP中,我使用的是Simple HTML DOM Parser类。
I have a HTML file which has multiple and diferents tags. 我有一个HTML文件,它有多个和不同的标签。
In this HTML there is an element like this: 在这个HTML中有一个这样的元素:
<a name="10418"><b> Hospitalist (Family Practitioner)</b></a>
So I would like to find that ' a ' element with has name="10418" 所以我想找到名字=“10418”的 ' a '元素
I've tried this with no luck, because I only want to get that string. 我试过这个没有运气,因为我只想得到那个字符串。
$html_object = str_get_html($url);
$html_object=$html_object->find('a');
foreach ($html_object as $o) {
$a= $o->find("b");
echo $a[0];
}
Try: 尝试:
$anchor = $html_object->find('a[name=10418]', 0);
echo $anchor->plaintext;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.