我想使用PHP正则表达式来匹配包含单词google
的所有链接。我试过这个:正则表达式以匹配包含“Google”的链接
$url = "http://www.google.com";
$html = file_get_contents($url);
preg_match_all('/<a.*(.*?)".*>(.*google.*?)<\/a>/i',$html,$links);
echo '<pre />';
print_r($links); // it should return 2 links 'About Google' & 'Go to Google English'
但是它什么都没有返回。为什么?
这里的“问题”是,当完美的解析器和XPath可用时,您正在使用正则表达式。 – 2011-03-06 10:36:00