By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,069 Members | 1,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,069 IT Pros & Developers. It's quick & easy.

matching across new lines

P: n/a
Hi,

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;
}
fclose($fp);
$match = array();
$pattern = '/' . EMAIL_TEXT_START_TOKEN . '(.*)' .
EMAIL_TEXT_END_TOKEN . '/';
preg_match($pattern, $file_contents, $match);

Anyway, any advice you have is greatly appreciated, - Dave
Mar 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

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

HTH,

John Peters

On Mar 4, 4:07 pm, "laredotorn...@zipmail.com"
<laredotorn...@zipmail.comwrote:
Hi,

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;
}
fclose($fp);
$match = array();
$pattern = '/' . EMAIL_TEXT_START_TOKEN . '(.*)' .
EMAIL_TEXT_END_TOKEN . '/';
preg_match($pattern, $file_contents, $match);

Anyway, any advice you have is greatly appreciated, - Dave
Mar 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.