PHP Function to replace all new line characters in a string with BR tag

There is an incredible but little known built-in function with PHP that replaces all new line characters within a string with html <br /> tags. Its perfect if you ever want to display the contents of a text area within HTML.

$str = nl2br($str);

This will replace all new line characters with valid XHTML <br /> tags.

There is also an optional parameter to turn of XHTML and just use traditional <br> tags.

$str = nl2br($str, false)

Plugin Auto-Updates break my site

For the first time in over 10 years, my RMTWeb site was down for four days as I struggled to figure out what had completely broken my wordpress installation. A blank white screen was all that greeted any visitor to the site. Scouring through the server logs revealed the culprit – Google Analytics! There seems to be a conflict between it and one of the ReWrite rules created by the WPSecurity Plugin. So it seems I had a choice to make – keep Google Analytics or keep WP Security…..

I first tried removing WP Security, but it places re-write rules in .htaccess files throughout the wordpress installation, so this didn’t solve the issue. Removing the Google Analytics plugin by deleting the whole folder out of FTP did the trick, and the site was back up and running in no time!