How can I make this string from a 'textarea' to be on one single line?

html, php

Solution

Replace all groups of whitespace with a single space:

$output = preg_replace('!\s+!', ' ', $input);

Problem

I have tried and tried and tried now. I have a mysql field (TEXT) which contains the value of a textarea. That is, if the text is written EXACTLY like this: ``` Hello. Hello. Hello. Hel lo. ``` Then thats how it will appear in the mysql field because Im using wordwrap and nl2br functions when inserting it there. Now, I am creating a dynamic page, where the 'meta description content' is updated with the 'TEXT' content, BUT, in one long string without any breaks and new lines. That said, I need to make text to be in one string. I have used this: ``` str_replace ("<br/>", "", $string); ``` This displays the text as one string, yes, but when viewing the source code of the page, you can see that the breaks are there, like this: ``` <meta name="description" content=" Hello. Hello. Hello. Hel lo." /> ``` I have also tried replacing the with '\n' and others, without success... How can I solve this irritating problem? Let me know if you need more input, and I will update this Q.

Original source