Search and replace with new lines?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I'm using PHP 5.  Does anyone know how I can do a regular expression
search and replace when the target string contains carriage returns
('\n')?  This is the code I have that isn't working ...

                        $pattern = '/' . TOTAL_START_TOKEN . '(.*)' .
                        $ecom_file_contents = preg_replace($pattern,
"", $ecom_file_contents);

When the target string contains ('\n'), the expression doesn't work.
When it doesn't contain that character, the search and replace works

Thanks for your help, - Dave

Re: Search and replace with new lines?

Quoted text here. Click to load it

Try the s modifier:  .... TOTAL_END_TOKEN . '/s';

Site Timeline