dapidmini dapidmini - 8 days ago 7
PHP Question

remove empty lines and convert into single space php

I have a data in mysql table:

<p>aaaa</p>
<p>&nbsp;</p>
<p>asd</p>


and I need to display it like this:

aaaa asd


But I can't seem to get it right.

First I'm using this code:

$string = htmlspecialchars_decode(stripslashes($string)); // $string contains data from the table


and I tried this: (from here)

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


and also this: (from here)

$string = str_replace(array("\n", "\r"), '', $string);


but nothing works!
when I use
echo $string;
it still shows an empty line. can anyone give a solution?

Answer

Can find the answer here. Or try: $line_out = preg_replace('/[\n\r]+/', '', $line_in);