FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » finding newlines
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: finding newlines [message #183934 is a reply to message #183933] Tue, 26 November 2013 18:46 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Denis McMahon wrote:

> On Mon, 25 Nov 2013 20:11:40 +0000, Denis McMahon wrote:
>> $lines=explode("\n",preg_replace("/[\r\n]+/","\n",$progressNote));
>
> or of course:
>
> $lines=preg_split("/[\r\n]+/",$progressNote);

Now that I told you. However, “of course” *that* is questionable: within
double-quotes, “\r” and “\n” are expanded as *string* escape sequences,
before preg_split() sees them. When in doubt, use either single-quotes or
double-quotes with double-backslash.

I prefer to use double-backslash also with single-quotes in case someone
decides in the future to support more escape sequences. The resulting code
style also is more consistent because with trailing backslash you *must* use
double-backslash unless you want to escape the string delimiter: '\' is
likely to become a syntax error (unterminated string literal); '\\' is not.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Lan Pc Login time
Next Topic: Check if $_GET contains something other than what's allowed
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 04:22:58 GMT 2024

Total time taken to generate the page: 0.04868 seconds