I see if if the first search braket is found on a line, and the last search breaket on another line... then the preg_replace won't work .... $string=" FILE THIS WILL NOT WORK SECTION "; $search='#(FILE)(.*)(SECTION)#e'; $output = preg_replace($search,"('')",$string); $string=" FILE BUT THIS WILL WORK ... SECTION "; $search='#(FILE)(.*)(SECTION)#e'; $output = preg_replace($search,"('')",$string); Code (markup):
for multiple lines you'll want to use the multiple line modifier 'm' http://php.net/manual/en/reference.pcre.pattern.modifiers.php
Can somebody give me a short example? how this : $search='#(FILE)(.*)(SECTION)#e'; should be changed?
$search='#FILE(.*?)SECTION#es'; PHP: ... are you sure you actually need the "e" (eval) modifier? Seeing your above code, I think you could get rid of it.
http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php#51739 See the paragraph at the end for a nice explanation of the difference between the s&m modifiers (ehem).