Jump to content

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.