Jump to content

[SOLVED] Removing comments


lococobra

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/59735-solved-removing-comments/
Share on other sites

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.