note 94425 deleted from function.preg-replace by danbrown

From: Date: Wed, 04 Nov 2009 15:02:42 +0000
Subject: note 94425 deleted from function.preg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162394@lists.php.net to get a copy of this message
Note Submitter: A dot Lepe dev+php at alepe dot com ---- If you want to remove multi-line comments from a file: <?php /* This type of comment * like in Javascript / C++ / Php / etc */ $content = preg_replace("/\/\*.*?\*\//s","",$content); ?> The modifier "s" do the trick ;) Note: In theory it will work. (I tested it in several codes and worked fine). But I recommend you test it before using it in production. Other alternative is: <?php $content = preg_replace( "/\/\/.*?\/?\*.+?(?=\n|\r)|\/\*[\s\S]*?\/\/[\s\S]*?\*\//", "",$content); ?> (Taken from: http://james.padolsey.com/ javascript/javascript-comment-removal-revisted/ )

« previous php.notes (#162394) next »