Basically I have this script that I’m trying to replace the literal text \r\n with <br /> for proper formatting. I’ve tried nl2br() and it didn’t replace the \r\n with <br />. Here’s the code.
$title = isset($post[0]) ? $post[0] : false;
$body = isset($post[1]) ? preg_replace('#(\r|\r\n|\n)#', '<br/>', $post[1]) : false;
echo $title."<br/>".$body;
You’ll need three
\\\. Inside single quotes,\\translates to\so\\\rbecomes\\rwhich gets fed to thepreg_replacefunciton.PREG engine has its own set of escape sequences and
\ris one of them which means ASCII character #13. To tell PREG engine to search for the literal\r, you need to pass the string\\rwhich needs to be escaped once more since you have it inside single quotes.