Thursday, November 11, 2010

Convert string with carriage returns to one line in php

I have a database string containing new lines characters (\n) and needed to print it out with no linebreaks -- since it was being printed as a javascript variable. This script does the trick:

$input = trim( preg_replace( '/\s+/', ' ', $input ) );

courtesy: http://www.codingforums.com/showthread.php?t=137009

No comments: