[PHP] Comparing files
Hi all, I have a simple question : how can I ensure that 2 files are identical ? How about this ? 8-- function files_identical($path1, $path2) { return (file_get_contents($path1) == file_get_contents($path2)); } 8-- Note that I would like to compare any type of files (text and binary). Thanks for any help, -- Mathieu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Comparing files
Yes! Thanks a lot, md5_file suits perfectly well my needs. I've read that 'exec'ing the md5 command is faster... I'll see when performance on large files will become an issue. Thanks again, -- Mathieu -Message d'origine- De : Thijs Lensselink [mailto:[EMAIL PROTECTED] Envoyé : Wednesday, March 12, 2008 12:09 PM À : php-general@lists.php.net Objet : Re: [PHP] Comparing files Quoting mathieu leddet [EMAIL PROTECTED]: Hi all, I have a simple question : how can I ensure that 2 files are identical ? How about this ? 8-- function files_identical($path1, $path2) { return (file_get_contents($path1) == file_get_contents($path2)); } 8-- Note that I would like to compare any type of files (text and binary). Thanks for any help, -- Mathieu You could use md5_file for this. Something like: function files_identical($path1, $path2) { return (md5_file($path1) == md5_file($path2)); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Match anything between two that is not a except if it is escaped...
Hi everyone, I am struggling with regular expression trying to match strings delimited by double quotes, but taking into consideration that \ is not a string ending character. ---8--- - $in = 'this is a string : Hi everyone my name is \Mathieu\! Here is a second string : PHP is just perfect'; // pattern for catching strings between $pattern = '#([^]*)#'; // surround matching string with HTML span code to highlight $replacement = 'b${1}/b'; // perform the reg exp replacement $out = preg_replace($pattern, $replacement, $in); ---8--- - $out contains : this is a string : bHi everyone my name is \/bMathieu\b!/b Here is a second string : bPHP is just perfect/b This behaviour is normal considering my pattern (anything between two that is not a ). But I don't know how to get this : this is a string : bHi everyone my name is \Mathieu\!/b Here is a second string : bPHP is just perfect/b I would like my pattern to express : Anything between two that is not a except if it is escaped. Thanks for reading me, any help in return is welcome ! -- Mathieu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Match anything between two that is not a exceptifit is escaped...
Thanks a lot Max (and Jochem), you solved my issue. Cheers from Bordeaux in France ! -- Mathieu, learning everyday. -Message d'origine- De : Max Antonov [mailto:[EMAIL PROTECTED] Envoyé : Thursday, January 17, 2008 12:36 PM À : php-general@lists.php.net Objet : Re: [PHP] Re: Match anything between two that is not a exceptifit is escaped... Jochem Maas writes: attend? don't understand what you mean BUT you have given the OP the answer by changing his regexp to include a [negative] look behind assertion for the backslash. :-) I hope, my regular expression answer the purpose, than need Mathieu (what mean abbreviation OP? can send direcly to my mailbox) -- Max Anotnov (idler at instanceof dot ru) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Match anything between two that is not a exceptifitisescaped...
Yes Jochem, I *now* know what lookbehind and lookahead assertions are. I think I am *now* able to use them when needed. Max, thanks for the link. -- Mathieu || _| |_ / \ | | | | | | | | | | | | |__| ;) -Message d'origine- De : Max Antonov [mailto:[EMAIL PROTECTED] Envoyé : Thursday, January 17, 2008 3:04 PM À : php-general@lists.php.net Objet : Re: [PHP] Re: Match anything between two that is not a exceptifitisescaped... Jochem Maas : mathieu leddet schreef: Thanks a lot Max (and Jochem), you solved my issue. PS - you solved the issue but did you learn what a [negative] look behind assertion is? Mathieu, I agree with Jochem. If you periodicaly solve issues, such this - you must know about behind assertions in pcre. I ask google, and google give me good manual. http://www.pcre.org/pcre.txt open this page and use brouser search interface to find section PCREPATTERN or PCRE REGULAR EXPRESSION DETAILS it is best manual about PCRE (IMHO) But I don't know - is php pcre fully compatible with pcre library. Also see documentation in php.net :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php