Dynamic Description New Line Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Dynamic Description New Line Problem

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Dynamic Description New Line Problem

Post 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.
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: Dynamic Description New Line Problem

Post 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);
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Dynamic Description New Line Problem

Post by Celauran »

If the line breaks are in the DB, you'd want to replace <br>, not \n
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: Dynamic Description New Line Problem

Post 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
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: Dynamic Description New Line Problem

Post 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 :(
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: Dynamic Description New Line Problem

Post 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
Post Reply