在PHP中比较两个.text文件(~1MB)

I'm writing a program using PHP and cUrl to save the HTML of a particular website to a server once in a while. I only want to actually save the file if something has changed on the website, though, so my question is: how do I compare a long text string (the newest HTML from cUrl) against an existing .txt file? The .txt file is approximately 700kB, to give you an idea of size. I'm mo

strcmp() is likely your best bet.

It returns 0 if the two strings are the same -

so

if(strcmp($savedHTML, $newHTML) !== 0) {

    save($newHTML); // this would be your own function for saving

}

Of course, this will not work if there is a minor difference, such as a timestamp that has a different value each time.

I don't know how well behaved the server at the website you are saving is, but if it behaves properly and the website is coded properly it should return a 304 Not Modified status if nothing has changed.

I know they are a couple of big ifs, but you should check that before attempting anything else.

See the section on return values.