List Info

Thread: note 78682 added to function.preg-replace




note 78682 added to function.preg-replace
user name
2007-10-23 05:32:25
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('/ss+/', ' ', $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  -- h
ttps://master.php.net/note/delete/78682/integrated
Del: useless     -- http
s://master.php.net/note/delete/78682/useless
Del: bad code    -- htt
ps://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     -- http
s://master.php.net/note/delete/78682/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78682
Reject      -- https://mast
er.php.net/note/reject/78682
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


note 78682 rejected from function.preg-replace by james
user name
2007-10-23 13:38:43
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('/ss+/', ' ', $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?

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )