inspireddesign Posted April 25, 2009 Share Posted April 25, 2009 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 More sharing options...
inspireddesign Posted April 25, 2009 Author Share Posted April 25, 2009 Can anyone help with this one? I'm really stuck ??? . Thanks a bunch. Link to comment https://forums.phpfreaks.com/topic/155615-var-not-passing/#findComment-819240 Share on other sites More sharing options...
KPH71 Posted April 25, 2009 Share Posted April 25, 2009 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 More sharing options...
inspireddesign Posted April 25, 2009 Author Share Posted April 25, 2009 Well, that works for the first word in the array but all the others get ignored? Strange but I'm sure there's a solution ??? Not sure what that might be though ???. We are on the right track. Link to comment https://forums.phpfreaks.com/topic/155615-var-not-passing/#findComment-819262 Share on other sites More sharing options...
KPH71 Posted April 25, 2009 Share Posted April 25, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.