himmer Posted May 24, 2009 Share Posted May 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/159515-ignore-carriage-return/ Share on other sites More sharing options...
nrg_alpha Posted May 24, 2009 Share Posted May 24, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/159515-ignore-carriage-return/#findComment-841418 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.