How do I compare two strings of HTML/JavaScript in PHP, for equality?

BruceS1970

New Member
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->real_escape_string()\[/code\] 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:\[code\]if ($saved == $content) return true;else return false;\[/code\]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:\[code\]$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)\[/code\]Second PHP file:\[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->query($query); $data = http://stackoverflow.com/questions/15560509/$result->fetch_assoc(); $saved = $data['content']; if ($saved == $content) echo '1'; else echo '0';\[/code\]
 
Back
Top