dapidmini dapidmini - 1 year ago 98
PHP Question

remove empty lines and convert into single space php

I have a data in mysql table:


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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download