Forum Moderators: coopster
I want to use preg_replace (or something else if that is faster ofcourse).
I want to replace single and multi line comments.
so comments like this:
// singel line/* single line comment */
/**
* multi line
* comment
**/
Also, i want some comment to be in place.
/*<![CDATA[*/ at the top of the page.
and
/*]]>*/ at the bottom of the page.
If this isn't good to do, then i can just add those myself at the top and bottom ofcourse :).
thx in advanced.
Have you considered strip_tags [php.net] and the optional
allowable_tagsargument?
I Think i have found it.
preg_replace('/(\/\*[\s\S]*?\*\/¦[\r]¦[\n]¦[\r\n])/', '', $buffer)
Thisway it removes all the comments, including the new-lines and puts everything close together.
The CSS still works like a charm :), and with the gz_handler it has become very small now :).
I Whas searching for this a long time, so that is why i asked here, but now i figured it out.
any comments are nice if there are any :).
// single line
comments in your regular expression pattern. I thought I would throw that in for good measure and while I was at it I took a stab at the CDATA comments. You'll notice that I used the .* notation and curbed the greediness by adding a "?" modifier just as you did. The only difference you see now though is that the pattern will indeed match -- even on newlines -- because I added the ("s") modifier to the end of the regular expression. I'm wondering if you didn't have it that way before and weren't getting what you expected ...? Here nor there, if you were, that is why.
$pattern = '/(\/\*(?!(<!\[CDATA¦]]>)).*?\*\/¦\/\/.*?[\r\n]+¦[\r\n]+)/s';
$buffer = preg_replace($pattern, '', $buffer);
I use it to send as litle data as possible to the users browser, to safe bandwith afcourse.
I Also gzip the css and js files with the use of the gz_handler :).
I Will try to use your RegExp :).
Ill keep ya posted :).
My regex? What do you mean? It's yours! I started with yours and went a little further, that's all ;)
By the way, don't forget if you cut and paste code from this forum you will need to rekey the pipe symbols (¦) as this forum breaks them.
I downloaded a program called 'The Regex Coach', and it did how it is named, it coached me :).
Now i only have one small problem with JS files.
They can have URL's in them, which contains [....]
You see my problem :).
Some sample code:
/**
* Function desciption
**/
function myFunction() {
window.open(/**/"http://www.domain.com/index.php", "", "width=250, height=130");
} My Regular Expression is the following:
'/\/\*.*?\*\/¦\/\/.*?[\r\n\>]¦\<\!--[\r\n]+¦[\t]+/s' Is there any way to let it be NOT when it starts with ( and ends with )?
Thx in advanced.
But i can't seem to get it to work :(.
I have this expression:
\/\*.*?\*\/¦\/\/(?!(w)).*?([\r\n])¦[\t]+ I tried to use "(?!(.*\)))", but has also no effect.
I Know i probably do something wrong, but i can't figure out what.