I'm trying to use curl to detect whether a piece of text exists in the source code of a remote webpage. For example, I'm trying to see if this string exists in the source:
<!-- BEGIN TEST CODE -->
If it exists in the HTML source code of a remote webpage (say, example.com) I want to echo "yes". If it doesn't exist in the source, I want it to echo "no".
This is what I've tried so far:
$ch = curl_init("http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$text = curl_exec($ch);
$test = strpos($text, "<!-- BEGIN TEST CODE -->");
if ($test==false)
{
echo "yes";
}else{
echo "no";
}
When I run it, it always outputs "yes". What's wrong in my code, and how should I do it correctly?