title: Check if string exists in a web page
body: <p>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: </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!-- BEGIN TEST CODE --&gt;
  </code></pre>
  
  <p>If it exists in the HTML source code of a remote webpage (say, <a href="http://www.example.com/" rel="nofollow">example.com</a>) I want to echo "yes". If it doesn't exist in the source, I want it to echo "no".</p>
  
  <p>This is what I've tried so far:</p>
  
  <pre class="lang-php prettyprint-override"><code>$ch = curl_init("http://www.example.com");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $text = curl_exec($ch);
  
  $test = strpos($text, "&lt;!-- BEGIN TEST CODE --&gt;");
  if ($test==false)
  {
      echo "yes";
  }else{
      echo "no";
  }
  </code></pre>
  
  <p>When I run it, it always outputs "yes". <strong>What's wrong in my code, and how should I do it correctly?</strong></p>