我需要检查网站外部的网页上是否有特定的单词。我已经尝试过file_get_contents(),但是它没有返回任何内容。有什么办法可以用PHP做到这一点?
编辑:这是我尝试过的:
$query = 'example';
$file = "https:// www.site.com/search?q=$query";
// tested url and it works, had to add space to post it
$contents = file_get_contents($file);
echo $contents;
我原以为它会输出整个页面供以后使用.includes()
,但它什么都不输出。
查看curl
以获取网页的内容。然后,您可以使用preg_match
查找单词。