lococobra Posted July 13, 2007 Share Posted July 13, 2007 So lets say I have some code such as... echo "test"; //here's some stuff i dont want to see echo "okay"; //other stuff echo "blah"; /* and a multi line comment That ends */ here This code is contained in $code Then I run this on it.... $code = preg_replace("/(\/\/)(.*?)([\n\r])/", '', $code); $code = preg_replace("/(\/\*)(.*?)(\*\/)/", '', $code); And it becomes... echo "test"; echo "okay"; echo "blah"; /* and a multi echo "text"; line comment That ends */ here Could someone tell me how to fix the pattern of the 2nd one? Quote Link to comment https://forums.phpfreaks.com/topic/59735-solved-removing-comments/ Share on other sites More sharing options...
effigy Posted July 13, 2007 Share Posted July 13, 2007 Why are you using capturing parentheses? A . will not cross new line boundaries without the /s modifier. Quote Link to comment https://forums.phpfreaks.com/topic/59735-solved-removing-comments/#findComment-297377 Share on other sites More sharing options...
lococobra Posted July 13, 2007 Author Share Posted July 13, 2007 Yeah, I figured it out already. All I had to do was add /s to the end. Quote Link to comment https://forums.phpfreaks.com/topic/59735-solved-removing-comments/#findComment-297480 Share on other sites More sharing options...
fachru Posted July 30, 2007 Share Posted July 30, 2007 i'm still newbie here....sorry i still don't get about how to eliminate comment between /*.... ..... multi line .....*/ tag where should i add /s ??? sorry still newbie ;D Quote Link to comment https://forums.phpfreaks.com/topic/59735-solved-removing-comments/#findComment-310733 Share on other sites More sharing options...
effigy Posted July 30, 2007 Share Posted July 30, 2007 Regular Expressions use patterns. Patterns must be kept within delimiters. Modifiers go behind the last delimiter, like so: /pattern/modifiers Quote Link to comment https://forums.phpfreaks.com/topic/59735-solved-removing-comments/#findComment-310894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.