note 78682 added to function.preg-replace

From: Date: Tue, 23 Oct 2007 10:32:25 +0000
Subject: note 78682 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-131656@lists.php.net to get a copy of this message
I am trying to build a function to pack a php script. I am using regular expressions to delete comments and whitespace: <?php // Delete //-comments: $code = preg_replace('/\/\/.*/', '', $code); // Delete /* */-comments: $code = preg_replace('/\/\*.*\*\//m', '', $code); // Delete excess whitespace: $code = preg_replace('/\s\s+/', ' ', $code); ?> I'm having trouble when removing /* */-comments. It doesn't get the multiline mode. So this he will delete: /* comment */ but not this: /* comment */ And when deleting the excess whitespace, also the EOL's get deleted so my code is returned in one big string, and I don't want that: I want to preserve the EOL's. any suggestions what I am doing wrong here? ---- Server IP: 83.137.20.135 Probable Submitter: 77.248.177.32 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/78682 Del: integrated -- https://master.php.net/note/delete/78682/integrated Del: useless -- https://master.php.net/note/delete/78682/useless Del: bad code -- https://master.php.net/note/delete/78682/bad+code Del: spam -- https://master.php.net/note/delete/78682/spam Del: non-english -- https://master.php.net/note/delete/78682/non-english Del: in docs -- https://master.php.net/note/delete/78682/in+docs Del: other reasons-- https://master.php.net/note/delete/78682 Reject -- https://master.php.net/note/reject/78682 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131656) next »