PHP spitting out n/n instead of new lines.

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
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

PHP spitting out n/n instead of new lines.

Post by evilcoder »

Hey guys,

Instead of my programme spitting out a mysql field like this on the page:

Code: Select all

WWE Smackdown – Here comes the pain will have blood also but will incorporate a fun loving Bra and Panty match.

After
It spits out:

Code: Select all

WWE Smackdown – Here comes the pain will have blood also but will incorporate a fun loving Bra and Panty match.\r\n\r\nAfter
I'm not sure why?

thanks guys
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

show your code

Mark
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

Code: Select all

<?php
$news_sql = "SELECT *
			 FROM article AS a
			 WHERE a.relcategory_id = '22'
			 AND a.article_viewable = '1'
			 ORDER BY a.article_creation DESC";
		
$news_result = mysql_query ( $news_sql ) or die ( "ERROR 1: " . mysql_error() );
while ( $news_array = mysql_fetch_array ( $news_result ) )
{
	$news_name = $news_array['article_name'];
	$news_id = $news_array['article_id'];
	$news_relcat = $news_array['relcategory_id'];
	$news_authorid = $news_array['reluser_id'];
	$news_date = $news_array['article_creation'];
	
	$template->allocate_blockvariables ( "news" , array ( 
										"TITLE" => $news_name ) );

	$category_sql = "SELECT *
					 FROM category AS cat
					 WHERE cat.category_id = '$news_relcat'";
	$category_result = mysql_query ( $category_sql ) or die ( "ERROR 3: " . mysql_error() );
	$category_array = mysql_fetch_array ( $category_result );
	
	$category_relcattype = $category_array[ "relcategorytype_id" ];
	$category_relcatname = $category_array[ "relcategoryname_id" ];
	
	$content_sql = "SELECT c.content_data , ct.categorytype_name , cn.categoryname_name , u.user_email , u.user_firstname , u.user_surname
					FROM content AS c , categorytype AS ct, categoryname AS cn , user AS u
					WHERE c.relarticle_id = '$news_id' 
					AND ct.categorytype_id = '$category_relcattype' 
					AND cn.categoryname_id = '$category_relcatname'  
					AND u.user_id = '$news_authorid'";
				
	$content_result = mysql_query ( $content_sql ) or die ( "ERROR 2: " . mysql_error() );
	
	while ( $content_array = mysql_fetch_array ( $content_result ) )
	{		
		$content = $content_array['content_data'];
		$category_name = $content_array['categoryname_name'];
		$category_type = $content_array['categorytype_name'];
		$author = $content_array['user_firstname'];
		$author_email = $content_array['user_email'];
		
		$article_url = str_replace ( " " , "_" , $news_name );
		
		$content = nl2br ( $content );
	
		$template->allocate_blockvariables ( "news.content" , array (
											 "CONTENT" => $content ,
											 "DATE" => $news_date ,
											 "CATNAME" => $category_name ,
											 "TYPENAME" => $category_type ,
											 "AUTHORNAME" => $author ,
											 "AUTHOREMAIL" => $author_email ,
											 "READMORE" => "Read Further" ,
											 "AURL" => $rootPath . FILE_VIEW . "/$category_type/$category_name/$article_url" ) );
	}					
}	
?>
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

its ok guys, used str_replace, and stripslashes to fix it :)
Post Reply