kooper Posted May 25, 2006 Share Posted May 25, 2006 how can i keep my text formating after its queried from mysqlas an exampleid if i posted this[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]hellohow are you[/quote]after its queried it becomes [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]hello how are you[/quote]also, is there an easy way to block html in someones post?i was thinking about useing bbcodei tryed $comment = htmlspecialchars($_POST[comment]); but it doesnt seem to do very much Quote Link to comment https://forums.phpfreaks.com/topic/10422-text-formating-after-mysql-query/ Share on other sites More sharing options...
Honoré Posted May 25, 2006 Share Posted May 25, 2006 Try the following script:[code]<html><head></head><body><p>You entered te following comment:</p><p>Without htmlspecialchars:</p><p><?phpecho $_POST['comment'];?></p><p>With htmlspecialchars:</p><p><?phpecho htmlspecialchars($_POST['comment']);?></p><p>Enter new comment:</p><form method="POST" action="<?php echo $PHP_SELF; ?>"><input name="comment" type="text" /><input name="submit" type="submit" value="submit" /></form></body></html>[/code]And enter the following text as comment:normal <b>bold</b> <i>italic</i>Don't you see a difference with or without htmlspecialchars? Quote Link to comment https://forums.phpfreaks.com/topic/10422-text-formating-after-mysql-query/#findComment-38860 Share on other sites More sharing options...
kooper Posted May 25, 2006 Author Share Posted May 25, 2006 thanks very muchi tryed adding it to the echo, which just rendered my bbcode useless.lolso i added it to the mysql insert and with a little playing around with it, it worked perfect, thanks alotnow there just the formating thing to get sorted Quote Link to comment https://forums.phpfreaks.com/topic/10422-text-formating-after-mysql-query/#findComment-38888 Share on other sites More sharing options...
wildteen88 Posted May 25, 2006 Share Posted May 25, 2006 if you want your line breaks to be preserved use nl2br, ie:[code]$comment = nl2br(htmlspecialchars($_POST[comment]));[/code]nlsbr converts new line characters (\r or \n) to a html line break (< br / >) Quote Link to comment https://forums.phpfreaks.com/topic/10422-text-formating-after-mysql-query/#findComment-38890 Share on other sites More sharing options...
kooper Posted May 25, 2006 Author Share Posted May 25, 2006 worked perfectly, thank you v much Quote Link to comment https://forums.phpfreaks.com/topic/10422-text-formating-after-mysql-query/#findComment-38893 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.