Jump to content

Var not passing?


inspireddesign

Recommended Posts

Hello Guys,

 

For some reason the $spamWord variable is not passing correctly in my script.  It shows as an ! mark.  Can someone help.  Thanks in advance.

 

Here:

 


<?php

            $resp = array("msg" => "Word/Phrase you entered may be considered spam: $spamWord");

?>

 


<?php

    function check_spam($input) {

        global $spamList;
        $resp = array();
    $check = strtolower( $input );
	$chkInput = trim($check);

		   foreach ( $spamList as $spamWord ) {
			  if ( strpos( $chkInput, strtolower( $spamWord ) ) !== false ) 
			  $foundSpamWord = true;				   	  
		   }				  
			  			   
        if (!$input) {

          	$resp = array('msg' => "Enter subject line");

        } else if ($foundSpamWord == true) {

            $resp = array("msg" => "Word/Phrase you entered may be considered spam: $spamWord");

        } else {

            $resp = array("msg" => "<img src=\"cmrk.jpg\" height=\"16\" width=\"16\" />");

        }

        return $resp;        
    }


?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/155615-var-not-passing/
Share on other sites

It may be because an exclamation mark is the last in your $spamList array. You need to stop the foreach statement after it finds spam or else it will continue through the array therefore changing the value of $spamWord.

 

<?php

            foreach ( $spamList as $spamWord ) {
              if ( strpos( $chkInput, strtolower( $spamWord ) ) !== false ) 
              $foundSpamWord = true;  
              break;                  
            }         

?>

 

Adding in the break above stops the foreach loop and therefore keeps the correct spamWord.

Link to comment
https://forums.phpfreaks.com/topic/155615-var-not-passing/#findComment-819259
Share on other sites

Sorry - mistake in my code

 

<?php

            foreach ( $spamList as $spamWord ) {
              if ( strpos( $chkInput, strtolower( $spamWord ) ) !== false ) 
              {
              $foundSpamWord = true;  
              break;   
              }               
            }         

?>

Link to comment
https://forums.phpfreaks.com/topic/155615-var-not-passing/#findComment-819263
Share on other sites

Archived

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

×
×
  • 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.