note 94425 added to function.preg-replace

From: Date: Wed, 04 Nov 2009 06:58:06 +0000
Subject: note 94425 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-162385@lists.php.net to get a copy of this message
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/ ) ---- Server IP: 69.147.83.197 Probable Submitter: 211.6.179.194 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/94425 Del: integrated -- https://master.php.net/note/delete/94425/integrated Del: useless -- https://master.php.net/note/delete/94425/useless Del: bad code -- https://master.php.net/note/delete/94425/bad+code Del: spam -- https://master.php.net/note/delete/94425/spam Del: non-english -- https://master.php.net/note/delete/94425/non-english Del: in docs -- https://master.php.net/note/delete/94425/in+docs Del: other reasons-- https://master.php.net/note/delete/94425 Reject -- https://master.php.net/note/reject/94425 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162385) next »