matching across new lines

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

Threaded View

I'm using PHP 4.4.4.  I'm reading the contents of a file and then
trying to extract contents between two string tokens.  Problem is,
tokens occur on different lines.  It seems that regular expressions
only match one line at a time.  Is there any way to make them span an
entire string?  Here's what I got

                $file_contents = "";
                $fp = fopen($email_templ_file, "r");
                while($line=trim(fread($fp, 102400))) {
                        $file_contents .= $line;
                $match = array();
                $pattern = '/' . EMAIL_TEXT_START_TOKEN . '(.*)' .
                preg_match($pattern, $file_contents, $match);

Anyway, any advice you have is greatly appreciated, - Dave

Re: matching across new lines


Try the dot all option (/s) to have the dot metachar match newlines as


John Peters

On Mar 4, 4:07 pm, ""
Quoted text here. Click to load it

Site Timeline