NYCPHP Meetup

[nycphp-talk] What does this code do?

Rolan Yang rolan at omnistep.com
Mon Mar 3 13:20:25 EST 2008


-- rada -- wrote:
> Hi all,
>
> I am trying to implement a user-input scrubbing function, more 
> specifically, normalize linebreaks from windows/mac to unix. I can 
> just do preg_replace but I saw this piece of code somewhere and don't 
> understand it enough to even know what to google.
>
> supposedly converts Windows CRLF  to Unix LF:
> $str =~ s/\r\n/\n/g;
>
> What does =~ do? I can RTFM if you point me to it :)
>
>
That is perl code which searches $str for "\r\n" and replaces it with '\n".
The same code in php would be   preg_replace('/\r\n/',"\n",$str);

~Rolan




More information about the talk mailing list