Jump to content

Delete All Html In Comments


wickedXxxxlegox

Recommended Posts

There's more than one way to skin this cat: htmlspecialchars(), strip_tags(), htmlentities(), etc. would all do the job.  Some people like to do it before inserting into DB, other like to do it while printing the content out.

 

http://www.php.net/strip_tags

http://www.php.net/htmlspecialchars

http://www.php.net/htmlentities

Link to comment
Share on other sites

htmlspecialchars () is definitely the way to go. htmlentities () is quite unnecessary as it does too much, and strip_slashes () is not recommended because you're just as likely to remove legit content with it.

 

However, this doesn't alleviate the need to Validate the Input you get from the user. The above methods are only Escaping Output, after all. Input validation is a quite wide and potential complex topic, so I recommend reading a few guides on how to do this.

Link to comment
Share on other sites

Okay, here's my commentstream.php code:

 

 






<?php
('includes/db_connect.php');
$result = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT 10");
htmlspecialchars ()
while($row = mysql_fetch_array($result))
  {
  echo "<div class='comment'><b><center>".$row['username'] . "</b></center><br><br><center><i>" . $row['comment']."</i></center><>";
  echo "<br/>";
  }
  ?>




 

 

 

 

Error:Parse error: syntax error, unexpected T_WHILE in /home/a1922355/public_html/commentstream.php on line 5

Link to comment
Share on other sites

Your call to htmlspecialchars() isn't necessary and shouldn't be there without being used. Check the PHP Manual..

<?php
('includes/db_connect.php');
$result = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT 10");
htmlspecialchars ()  // <--- Why is this even here? It's not being called right, not ending with a ; .  
while($row = mysql_fetch_array($result))
 {
 echo "<div class='comment'><b><center>".$row['username'] . "</b></center><br><br><center><i>" . $row['comment']."</i></center><>";
 echo "<br/>";
 }
 ?>

Link to comment
Share on other sites

Hello all...

 

I am working on a website, but I have a comments system and my 'good' ole friend is using HTML redirects...

-_-

 

 

So, I am trying to delete all code that shows up in comments. Basically what I want to do is have it so that <b> = [bLOCKED].

 

Here's my code:

<meta http-equiv="Refresh" content="0;url=home.php" />
<?php
include('includes/db_connect.php')

$username = mysql_real_escape_string($username);
$comment = mysql_real_escape_string($comment);

mysql_query("INSERT INTO comments (username, comment) VALUES ('$_POST[username]','$_POST[comment]')");
?>

 

Thanks! :tease-01:

Link to comment
Share on other sites

You best bet is to use Regex for this..so I´m moving this to that forum.

 

Moving back, this is not a regex problem at all. As jesi pointed out, it was already answered in his original post.

 

Edit:

Looks like gurus cannot move anymore. Either or, it is not a regex issue.

Edited by premiso
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.