your.syndrome Posted December 3, 2008 Share Posted December 3, 2008 Hi, I've got a comments form on my site. I've tried creating line breaks in my textarea box which then gets sent to the SQL, I've looked in the SQL and it is displaying in phpmyadmin that the line breaks are there. But when they get selected back to the page to be displayed it doesn't post the <br> tags or \n. I've viewed the source and the breaks are there in the white space just no HTML tags. Any help? Ask what bits of code you might need to see and i'll post them straight away Quote Link to comment Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 nl2br Should solve your problem. Quote Link to comment Share on other sites More sharing options...
peranha Posted December 3, 2008 Share Posted December 3, 2008 nl2br() is what you are looking for I believe Quote Link to comment Share on other sites More sharing options...
your.syndrome Posted December 3, 2008 Author Share Posted December 3, 2008 Thanks for the reply. I have been searching around and tried to implement that but couldnt get it to work This is the code I'm using to retrieve the 'posts' <? while ($row = mysql_fetch_array($result)) { $ename = stripslashes($row['name']); $eemail = stripslashes($row['email']); $epost = stripslashes($row['post']); $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5(strtolower($eemail))."&default=".urlencode($default)."&size=70"; echo('<li><div class="meta"><img src="'.$grav_url.'" alt="Gravatar" /><p>'.$ename.'</p></div><div class="shout"><p>'.$epost.'</p></div></li>'); } ?> Quote Link to comment Share on other sites More sharing options...
peranha Posted December 3, 2008 Share Posted December 3, 2008 $epost = nl2br(stripslashes($row['post'])); Quote Link to comment Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 <?php while ($row = mysql_fetch_array($result)) { $ename = stripslashes($row['name']); $eemail = stripslashes($row['email']); $epost = nl2br(stripslashes($row['post'])); $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5(strtolower($eemail))."&default=".urlencode($default)."&size=70"; echo('<li><div class="meta"><img src="'.$grav_url.'" alt="Gravatar" /><p>'.$ename.'</p></div><div class="shout"><p>'.$epost.'</p></div></li>'); } ?> While I look at the code, a rule of thumb is you should never stripslashes on data coming out of database. You should also escape data with mysql_real_escape_string that is going into the DB. Anyhow that should work. Quote Link to comment Share on other sites More sharing options...
your.syndrome Posted December 3, 2008 Author Share Posted December 3, 2008 Thanks guys! Works wonderfully! If you've got a link you'd like to be credited for I'll pop it on the site. Quote Link to comment Share on other sites More sharing options...
peranha Posted December 3, 2008 Share Posted December 3, 2008 also on a side note, never use short php tags. <? always use the full <?php opening tag as short tags may not be supported on the server. Quote Link to comment Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 Thanks guys! Works wonderfully! If you've got a link you'd like to be credited for I'll pop it on the site. Just link back to phpfreaks, never hurts to help promote the site you got your answer from. Quote Link to comment Share on other sites More sharing options...
aledog Posted February 4, 2009 Share Posted February 4, 2009 some body of you guys can help me in this crack.... i just want to add a defoult avatar img if this search can get any result. this is a smarty code but its break. <img border="0" {if $resultsRow.user_id==''} src='{$base_url}application/images/default_avatar_thumb.jpg' {else} src='{$base_url}/application/content/profiles/{$resultsRow.user_id}_medium.jpg' {/if}/> Quote Link to comment Share on other sites More sharing options...
premiso Posted February 4, 2009 Share Posted February 4, 2009 some body of you guys can help me in this crack.... i just want to add a defoult avatar img if this search can get any result. this is a smarty code but its break. <img border="0" {if $resultsRow.user_id==''} src='{$base_url}application/images/default_avatar_thumb.jpg' {else} src='{$base_url}/application/content/profiles/{$resultsRow.user_id}_medium.jpg' {/if}/> Don't hijack, create your own thread. It should be created in the 3rd party forum as well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.