Reputation:
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.
Upvotes: 4
Views: 2414
Reputation: 625287
Replace all groups of whitespace with a single space:
$output = preg_replace('!\s+!', ' ', $input);
Upvotes: 10
Reputation: 41
You might try to something like this str_replace("\n\r", "", $string); I have found that sometimes the return character \r is hiding in there someplace.
Upvotes: 0
Reputation: 2109
handy function:
function removeEmptyLines($s) {
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $s);
}
Upvotes: 1