我有一个脚本,我写了扫描几个网站的谷歌链接,以确保它在那里。由于某种原因,我的脚本不起作用。当我在http://www.regexr.com/检查时,它可以正常工作,但不能在实时实施中使用。
它应该找到的链接示例:
https://plus.google.com/+VincentsHeatingPlumbingIncPortHuronTownship/about?hl=en
preg_match我正在使用:
if (preg_match_all("/(.*)plus.google.com(.*)/", $attributeValue->value))
{
$googleLinkCount ++;
$googleLinkHrefs[] = $attributeValue->value;
}
答案 0 :(得分:4)
不要使用正则表达式,请使用parse_url
:
if (parse_url($attributeValue->value, PHP_URL_HOST) === 'plus.google.com') {
// host is plus.google.com
}