How can I make this line from "textarea" for one line?

I tried, tried and tried.

I have a mysql field (TEXT) that contains the textarea value. That is, if the text is written EXACTLY as follows:

   Hello. Hello.
   Hello.
   Hel
   lo.

Then, as it will display in the mysql field, because Im uses the wordwrap and nl2br functions when pasting there.

Now I am creating a dynamic page where the “metadata description content” is updated with the contents of “TEXT”, BUT, in one long line without any breaks or new lines.

However, I need to make the text on one line.

I used this:

  str_replace ("<br/>", "", $string);

This displays the text as a single line, yes, but when viewing the source code of the page, you can see that there are gaps, for example:

<meta name="description" content="
   Hello. Hello.
   Hello.
   Hel
   lo." />


" \n" , ...

?

, , Q.

+3
4

:

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

"\n" "".

+1

convenient function:

function removeEmptyLines($s) {
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $s);
}
+1
source

You can try something like str_replace ("\ n \ r", "", $ string); I found that sometimes the returned \ character is hiding somewhere.

0
source

Source: https://habr.com/ru/post/1723598/


All Articles