Jump to content

Ignore Carriage Return


himmer

Recommended Posts

Hey all,

 

I was wondering how to ignore carriage returns.

 

ex.

starts with a numeric value \r

<text><line1>/r

<text><line2>/r

<text><line3>/r

<desired text>/r

 

line1, line2, line3 are varing.  Sometimes it is until line2 or line1.  But the end pattern search is always the desired text

 

Question?

How can you start from the numeric value and end at the desired text if lines vary?

 

Any help would be appreciated

Link to comment
https://forums.phpfreaks.com/topic/159515-ignore-carriage-return/
Share on other sites

Hmmm... Not sure what you mean by 'ignore return carriages' to be honest..if by this is you mean a pattern that doesn't get snagged on return crriages / new lines, perhaps something along the lines of...

 

preg_match('#^[0-9]+.+?<desired text>#s', $str, $match);
//$match[0] represents what the whole pattern has matched.

?

 

Of course, change $str to whatever string you are checking. Without seeing an actual example string (instead of some simplified placeholder), something tells me there's more to it than this.

 

In any case, the dot_match_all character (.) normally matches anything (except a new line - \n). Since your sample is scattered across multiple lines, you can use the s modifier after the closing delimiter (this enables the dot to match even newlines).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.