Jump to content


Photo

text formating after mysql query


  • Please log in to reply
4 replies to this topic

#1 kooper

kooper
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 May 2006 - 09:56 AM

how can i keep my text formating after its queried from mysql
as an example

id if i posted this
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
hello

how 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 bbcode
i tryed $comment = htmlspecialchars($_POST[comment]); but it doesnt seem to do very much
if ($2b || !$2b)
{
echo "that is the question";
}

#2 Honoré

Honoré
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationAntwerp - Belgium

Posted 25 May 2006 - 11:12 AM

Try the following script:
<html><head></head><body>
<p>You entered te following comment:</p>
<p>Without htmlspecialchars:</p>
<p>
<?php
echo $_POST['comment'];
?>
</p>
<p>With htmlspecialchars:</p>
<p>
<?php
echo 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>
And enter the following text as comment:
normal <b>bold</b> <i>italic</i>
Don't you see a difference with or without htmlspecialchars?

#3 kooper

kooper
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 May 2006 - 12:41 PM

thanks very much
i tryed adding it to the echo, which just rendered my bbcode useless.lol
so i added it to the mysql insert and with a little playing around with it, it worked perfect, thanks alot

now there just the formating thing to get sorted
if ($2b || !$2b)
{
echo "that is the question";
}

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 May 2006 - 12:46 PM

if you want your line breaks to be preserved use nl2br, ie:
$comment = nl2br(htmlspecialchars($_POST[comment]));

nlsbr converts new line characters (\r or \n) to a html line break (< br / >)

#5 kooper

kooper
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 May 2006 - 12:50 PM

worked perfectly, thank you v much
if ($2b || !$2b)
{
echo "that is the question";
}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users