Hello, in my site's comments page, sometimes users write comments like Hfgdgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg and that crashes my template. Is there anyway to detect and remove that sh*t ? Thanks!
I'm sure there will be a way. The code will depend on what language your comments page is written in. Why not post the URL here so that we can look at it for you ?
ye bro. There's always a way for these kind of things! You can do validation with javascript or PHP, but PHP is preferable because users can still bypass javascript by simple disabling it on their browser.
<?php // Change '20' to what ever you want define(MAX_WORD_LENGTH, 20); $userComment = 'I am a troll that uses really stupid looooooooooooooooooooong words'; // remove all long words $a = explode(' ', trim($userComment)); foreach ($a as $k => $v) if (strlen($v) > MAX_WORD_LENGTH) unset($a[$k]); $userComment = implode(' ', $a); // now $userComment has the same comment with all long words removed ?> PHP:
I hate comments like this. What is the point in giving the link of w3schools.com/php/default.asp ? Give me my seconds back in reading your comment. Yes! that is what I look for, thanks a lot man.