Replace everything between two tags

Possible duplicate:
Insert a line between two points using PHP

How can I replace everything between <!-- START NOT PRINT --> and <!-- END NO PRINT --> ?

The following code works well, but whenever there are two or more instances, it goes wrong.

Then it replaces everything between the first tag and the last tag. But he has to remove everything between two tags that belong to each other. This is my code:

 $pageData['raw_content'] = preg_replace('/<!--[ ]*START[ ]*NO[ ]*PRINT[ ]*-->(.*)<!--[ ]*END[ ]*NO[ ]*PRINT[ ]*-->/si', '', $pageData['raw_content']); 
+4
source share
1 answer

You are greedy.

You need an inanimate modifier :

 '/<!--[ ]*START[ ]*NO[ ]*PRINT[ ]*-->(.*?)<!--[ ]*END[ ]*NO[ ]*PRINT[ ]*-->/si' 

Note that .* Has become .*? .

+9
source

All Articles