Jump to content

Archived

This topic is now archived and is closed to further replies.

kooper

text formating after mysql query

Recommended Posts

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

Share this post


Link to post
Share on other sites
Try the following script:
[code]
<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>
[/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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 / >)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.