HueyJib Posted September 24, 2008 Share Posted September 24, 2008 Hi. I scripted my own pastebin site in php and I'm using a mysql database to store pastes. The problem is, I post the content like this: This Is The Content And it shows up just like that in the db table. Now, when I echo that content to the site, it shows up like this: This Is The Content How do I fix that? This is what I use to get the info from the table. $host="..."; $username="..."; $password="..."; $db_name="..."; $tbl_name="..."; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $pn=$_GET['pn']; $sql="SELECT * FROM $tbl_name WHERE pn='$pn'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); <tr> <td width="100%" align="center" bgcolor="#E6E6E6"><font face="Verdana" size="2"><strong>Content</strong></font></td> </tr> <tr> <td bgcolor="#FFFFFF"><font face="Verdana" size="2"><? echo $rows['text']; ?></font></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/125674-paste-problem/ Share on other sites More sharing options...
mrMarcus Posted September 24, 2008 Share Posted September 24, 2008 use nl2br(); this will store the integrity of your line breaks. http://ca.php.net/manual/en/function.nl2br.php it should help. Quote Link to comment https://forums.phpfreaks.com/topic/125674-paste-problem/#findComment-649813 Share on other sites More sharing options...
HueyJib Posted September 24, 2008 Author Share Posted September 24, 2008 use nl2br(); this will store the integrity of your line breaks. http://ca.php.net/manual/en/function.nl2br.php it should help. Aha! It worked. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/125674-paste-problem/#findComment-649898 Share on other sites More sharing options...
HueyJib Posted September 24, 2008 Author Share Posted September 24, 2008 Sorry for double post but I have a new question. One time I pasted a php/html code and it turned out it actually did the code as if I wanted it to work. For example, if I pasted this: <a href="http://www.phpfreaks.com/forums">PHP Help Forum</a> It would come out like this: PHP Help Forum How do I turn script code into raw text so it doesn't do the example above. Quote Link to comment https://forums.phpfreaks.com/topic/125674-paste-problem/#findComment-649907 Share on other sites More sharing options...
Stefan Posted September 26, 2008 Share Posted September 26, 2008 If I recall correctly than the html tags are <pre>your code here</pre>! This should keep all formatting and display as plain text or something of the like . . Quote Link to comment https://forums.phpfreaks.com/topic/125674-paste-problem/#findComment-651155 Share on other sites More sharing options...
mrMarcus Posted September 26, 2008 Share Posted September 26, 2008 Sorry for double post but I have a new question. One time I pasted a php/html code and it turned out it actually did the code as if I wanted it to work. For example, if I pasted this: <a href="http://www.phpfreaks.com/forums">PHP Help Forum</a> It would come out like this: PHP Help Forum How do I turn script code into raw text so it doesn't do the example above. i guess it kinda depends on how you want it to be viewed/stored. do you just want the link name and not the href attached with it? Quote Link to comment https://forums.phpfreaks.com/topic/125674-paste-problem/#findComment-651243 Share on other sites More sharing options...
Stefan Posted September 29, 2008 Share Posted September 29, 2008 Ooops! Sorry about that! I wrote, use tags 'pre and end pre' or try this link http://www.w3schools.com/TAGS/tag_pre.asp but mrMarcus has a point! Quote Link to comment https://forums.phpfreaks.com/topic/125674-paste-problem/#findComment-652927 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.