note 78682 rejected from function.preg-replace by james
| From: | james@php.net | Date: | Tue, 23 Oct 2007 18:38:43 +0000 |
| Subject: | note 78682 rejected from function.preg-replace by james | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-131665@lists.php.net to get a copy of this message | ||
Note Submitter: giel dot berkers at gmail dot com
----
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?