title: How do I compare two strings of HTML/JavaScript in PHP, for equality?
body: <p>I have a PHP program that stores the HTML/JavaScript contents of a webpage in a MySQL database. The contents are obtained using cURL, and are then subjected to <code>$mysqli-&gt;real_escape_string()</code> before being stored in the table as a longtext.</p>
  
  <p>Later, I have to once again use cURL to get the HTML/JavaScript contents of the webpage and retrieve those which I stored in the database.</p>
  
  <p>At this point, I need to compare them to see whether changes have been made or not in the code. I've tried using:</p>
  
  <pre><code>if ($saved == $content)
     return true;
  else
     return false;
  </code></pre>
  
  <p>However, this always returns false, even when no changes have been made to the code. Upon using cURL the second time, I am not escaping the string, so that isn't the issue. I've compared the two pieces of code, but I can't visually discern any differences.</p>
  
  <p>How can I compare the two strings so that it will accurately return whether any change has been made or not?</p>
  
  <p>I should also mention that both files execute just fine, except that the second one always returns false.</p>
  
  <p>First PHP file:</p>
  
  <pre><code>$url = "www.example.com";
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $content = $mysqli-&gt;real_escape_string(curl_exec($ch));
  curl_close($ch);
  
  $query = "INSERT INTO saved (url, content)
                VALUES ('$url', '$content')";
  
  $mysqli-&gt;query($query)
  </code></pre>
  
  <p>Second PHP file:</p>
  
  <pre><code>$url = "www.google.com";
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $content = curl_exec($ch);
  curl_close($ch);
  
  $query = "SELECT content
            FROM saved
            WHERE url = '$url'";
  
  $result = $mysqli-&gt;query($query);
  $data = $result-&gt;fetch_assoc();
  $saved = $data['content'];
  
  if ($saved == $content)
      echo '1';
  else
      echo '0';
  </code></pre>