Ok - cleaning my string like this:
$clean_string = preg_replace("/[\n\r]/"," ",trim($dirty_string));
.. Echo it out to the screen and it works - one lovely big lump of text with no newlines.
INSERT it into a LONGTEXT type field in MySQL - then preview the resulting data in Sequel Pro - and for some reason it has new lines. Loads of them, just like it did when it was new, before I cleaned it.
What am I doing wrong? Is it LONGTEXT?
This is what the html source looks like when I use the content of a SO page as a the string - note the many spaces and newlines - even when cleaned!
mysql - Trouble with CONCAT and Longtext - Stack Overflow
That should work. Also there really isn't any need to use preg_replace here--
$clean_str = str_replace(array("\r", "\n"), '', $dirty_string) will work just fine, and will be a little faster.
Solved by using this:
$clean_str = str_replace(array("\r", "\n"), '', $dirty_string);
BUT - replacing double quotes for single quotes. Works now.
$clean_str = str_replace(array('\r', '\n'), '', $dirty_string);
Thanks mfonda for getting me close!
$clean_string = preg_replace('/\s+/m', ' ',trim($string)); will replace every "space sequence" into a single space. Try it and see if it works as expected.
How about trimming AFTER removing all newlines?
$clean_str = trim(str_replace(array("\r", "\n"), '', $dirty_string));