Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts

    For Each Loop Help

    The below loop only seems to increment $abusecount for the first value in the array - if $q contains any of the other array values the script executes. What have I done wrong?

    PHP Code:
    $stopwords = array('<''>''bcc:''cc:''a href''[url]');
    $abusecount 0;
    foreach (
    $stopwords as $check){
      if (
    strpos($q$check) > 0){
        
    $abusecount++;
      }
    }
        
    if (
    $abusecount 0){
      die();
    } else {
      
    // Execute


  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The strpos() function returns the position of the string, if it is found, and "false", if it is not. If the string is found in the first byte, i.e. the "0"th byte, strpos() returns "0". Therefore, you cannot do if (strpos($q, $check) > 0), you must instead do if (strpos($q, $check) === false) {/*do false logic */} else {$abusecount++;}

    This is covered in depth in the PHP manual.

  • #3
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Ah yes, thanks Fumigator.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •