Page 1 of 1

Dynamic Description New Line Problem

Posted: Wed Nov 17, 2010 9:53 am
by agriz
Hi,

http://bit.ly/9TYQW7

The above link is an example for a problem. If you see the source, the description is not good. But i don't know how to remove the new line.

* While i insert the data in mysql, i didn't use any formatting.
* tried nl2br and then tried to remove br
* tried \n to space

But the description still have new line.

Re: Dynamic Description New Line Problem

Posted: Wed Nov 17, 2010 10:49 am
by Celauran
I'm assuming you're referring to the blank line between "by Charlie Chaplin" and "Mirror is..."? There are definitely two line breaks in there. If you're sure they aren't in the database, then I'd look at the code where the SQL results are being echoed/printed.

Re: Dynamic Description New Line Problem

Posted: Wed Nov 17, 2010 10:58 am
by agriz
In DB

It has two line breaks.

This is the following code for description

Code: Select all

$description = str_replace('\n',"",$description);
$description = substr($description, 0, 100);

Re: Dynamic Description New Line Problem

Posted: Wed Nov 17, 2010 11:01 am
by Celauran
If the line breaks are in the DB, you'd want to replace <br>, not \n

Re: Dynamic Description New Line Problem

Posted: Wed Nov 17, 2010 11:11 am
by agriz
I tried the following

Code: Select all

$description = str_replace('<br />',"",$description);
$description = str_replace('<br>',"",$description);
But still i have that problem

Re: Dynamic Description New Line Problem

Posted: Wed Nov 17, 2010 11:14 am
by agriz
I tried this too

Code: Select all

$description = nl2br($description);
$description = str_replace('<br />',"",$description);
$description = str_replace('<br>',"",$description);
But not working :(

Re: Dynamic Description New Line Problem

Posted: Wed Nov 17, 2010 11:27 am
by agriz
As a quick fix i did like this

Code: Select all

$description_arr = explode(" ",$description);
$description = '';
foreach($description_arr as $meta_d){
	$description .= trim($meta_d)." ";
}
But i am not satisfied with this method.
Please let me know some good method