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 $mysqli->real_escape_string() before being stored in the table as a longtext.
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.
At this point, I need to compare them to see whether changes have been made or not in the code. I've tried using:
if ($saved == $content)
return true;
else
return false;
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.
How can I compare the two strings so that it will accurately return whether any change has been made or not?
I should also mention that both files execute just fine, except that the second one always returns false.
First PHP file:
$url = "www.example.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = $mysqli->real_escape_string(curl_exec($ch));
curl_close($ch);
$query = "INSERT INTO saved (url, content)
VALUES ('$url', '$content')";
$mysqli->query($query)
Second PHP file:
$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->query($query);
$data = $result->fetch_assoc();
$saved = $data['content'];
if ($saved == $content)
echo '1';
else
echo '0';