PHP DOMDocument-匹配并删除URL
我正在尝试使用DOM从html页面提取链接:PHP DOMDocument-匹配并删除URL,dom,Dom,我正在尝试使用DOM从html页面提取链接: $html = file_get_contents('links.html'); $DOM = new DOMDocument(); $DOM->loadHTML($html); $a = $DOM->getElementsByTagName('a'); foreach($a as $link){ //echo out the href attribute of the <A> tag. echo $link-
$html = file_get_contents('links.html');
$DOM = new DOMDocument();
$DOM->loadHTML($html);
$a = $DOM->getElementsByTagName('a');
foreach($a as $link){
//echo out the href attribute of the <A> tag.
echo $link->getAttribute('href').'<br/>';
}
我想删除所有匹配dontwantthisdomain.com、dontwantthisdomain2.com和dontwantthisdomain3.com的结果,因此输出如下所示:
http://domain1.com/page-X-on-domain-com.html
http://domain.com/page-XZ-on-domain-com.html
http://domain3.com/page-XYZ-on-domain3-com.html
有什么想法吗?:) 我认为你应该使用正则表达式。用谷歌搜索它,玩得开心
$x=newdomxpath($DOM)$x->query('//a/@href/[not(contains(text(),“dontwantthisdomain”)))]代码>:P@yann-米林,你能看一下让我知道你的想法吗?谢谢pal@kojiro:表示您的代码导致错误。你能帮我吗?谢谢:)排序为$html=preg#u replace(“##i”、“$1”、$html);
http://domain1.com/page-X-on-domain-com.html
http://domain.com/page-XZ-on-domain-com.html
http://domain3.com/page-XYZ-on-domain3-com.html