Finding hidden line breaks in output for troubleshooting PHP scripts that output to plain text, CSV, and HTML file formats

Sometimes, there are just weird things with line breaks — it’s really hard to tell what type of line break is embedded in certain data.  Sometimes, text entered from a form with line breaks throws the output off, especially if your script needs to break the text or often the data feed down by line (also referred to as a row).

If you can capture the text in the $text variable, this will output it and find those line break offenders.  Throw Mac keyboard input into the mix, and you can spend hours trying to find these things so your script reads and breaks up the data properly.


echo str_replace(array('\r\n', '\r', '\n', '\t'), array('\\r\\n', '\\r', '\\n', '\\t'), $text);

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *