cURL检查网站上是否存在文字

时间:2016-05-31 13:21:08

标签: php curl

尝试查看IG acc是使用还是免费,但即使该帐户存在,它也总是返回false ...

<?php
$ch = curl_init("http://www.instagram.com/asd9usa0d0sad90sa90a09d");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$text = curl_exec($ch);
$test = strpos($text, "Sorry, this page");

print_r($text);

if ($test==false)
{
    echo "Username exists";
}
else
{
    echo "Username does not exist";
}

?>

如果IG acc不存在,例如instagram.com/basdlkasld4则会消失&#34;抱歉,此页面不可用。&#34;。

1 个答案:

答案 0 :(得分:1)

该网址在到达抱歉,此页面结果之前重定向了几次。如果添加以下行,Curl将正确遵循重定向。

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
相关问题