How to detect if keyword is too long

Discussion in 'Programming' started by CasTex, Jul 13, 2010.

  1. #1
    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!
     
    CasTex, Jul 13, 2010 IP
  2. wheeliebin

    wheeliebin Guest

    Messages:
    50
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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 ?
     
    wheeliebin, Jul 13, 2010 IP
  3. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #3
    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.
     
    Rainulf, Jul 13, 2010 IP
  4. CasTex

    CasTex Member

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    So ?? How to fix that ?
     
    CasTex, Jul 14, 2010 IP
  5. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #5
    There's nothing broken so there's no need to fix. Just use PHP instead of javascript. Study PHP here :)
     
    Rainulf, Jul 14, 2010 IP
  6. inspiroHost

    inspiroHost Peon

    Messages:
    989
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    What comment script are you using? Is it part of Wordpress?
     
    inspiroHost, Jul 14, 2010 IP
  7. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    
    <?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:
     
    Deacalion, Jul 14, 2010 IP
  8. CasTex

    CasTex Member

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    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.
     
    CasTex, Jul 15, 2010 IP