redarrow Posted June 8, 2006 Share Posted June 8, 2006 Advance thank you.The varable that holds the information is $message.how can i valadate what words are in the message verable like this.example:[code]$words=array("@" , "{ "," , "$" , " (" , " } " , "+" , "," )if($words==$message) {echo " sorry charecter used not allowed";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/ Share on other sites More sharing options...
redarrow Posted June 8, 2006 Author Share Posted June 8, 2006 This will replace the words not wanted but i want the same format but halting and echo a message cheers.example:[code]$mess=array("@","*","$","'","{","}",";","<br>","mysql","connect","</br>","password","money","scam",".","com","net","uk");$message=str_replace($mess,"xxx" ,$message);echo $message; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43126 Share on other sites More sharing options...
wisewood Posted June 8, 2006 Share Posted June 8, 2006 foreach($mess as $val) {$string = $mesage;if (eregi('$val', $string)) { echo "Sorry, $val is not allowed.";}} Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43129 Share on other sites More sharing options...
redarrow Posted June 8, 2006 Author Share Posted June 8, 2006 I got this so far but dosent work.The varable is comming from the form so far before the database insert cheers.[code]$mess=array("@","*","$","'","{","}",";","<br>","mysql","connect","</br>","password","money","scam",".","com","net","uk");foreach($mess as $val) {$string = $message;if (eregi('$val', $string)) {echo "Sorry, $val is not allowed.";}}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43134 Share on other sites More sharing options...
redarrow Posted June 8, 2006 Author Share Posted June 8, 2006 my error[code]Sorry, @ is not allowed.Warning: ereg(): REG_BADRPT in C:\Program Files\Apache Group\Apache2\htdocs\collage\bands\mail\mail.php on line 43Sorry, $ is not allowed.Sorry, . is not allowed[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43138 Share on other sites More sharing options...
wisewood Posted June 8, 2006 Share Posted June 8, 2006 <?php// only problem with this is that the word "coming" (for example) contains com, which is not allowed in your list.// to get around this, put a space either side of com, filter for .com instead.$message = "Your message here probably from a from on the previous page";$mess=array("@", "*", "$", "'", "{", "}", "<br>", "mysql", "connect", "</br>", "password", "money", "scam", ".", "com", "net", "uk");foreach($mess as $val) {$invalid = strpos($message, $val);if($invalid===FALSE) { $count++; }}$array_count = count($mess, COUNT_RECURSIVE);if($count==$array_count) { echo "Contains no illegal characters";}else { echo "Your message contains illegal words / characters"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43147 Share on other sites More sharing options...
redarrow Posted June 8, 2006 Author Share Posted June 8, 2006 Can some one brake this down to a babys level please lol cheers mate!wisewood thats agrate bit of programming cheers please exsplain the code i only understand 50% of it beg you.thanks redarrow. Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43159 Share on other sites More sharing options...
wisewood Posted June 8, 2006 Share Posted June 8, 2006 // Your message that you want to check for illegal characters/words.// $_POST[message] for example$message = "Your message here probably from a from on the previous page";// Your array of things that you do not want added to the database$mess=array("@", "*", "$", "'", "{", "}", "<br>", "mysql", "connect", "</br>", "password", "money", "scam", ".", "com", "net", "uk");// For each of the values in the $mess array, set it as $val and check if it exists in the $message variable.// If it does not exist, add 1 to the $count variable.foreach($mess as $val) {$invalid = strpos($message, $val);if($invalid===FALSE) { $count++; }}// Count the number of words/characters that are in the array$array_count = count($mess, COUNT_RECURSIVE);// If the $count variable is the same as the $array_count variable, there are no illegal charactersif($count==$array_count) { echo "Contains no illegal characters";}// if the $count and $array_count variables do not match, there must be at least one illegal character in the $message variable.else { echo "Your message contains illegal words / characters"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43169 Share on other sites More sharing options...
redarrow Posted June 8, 2006 Author Share Posted June 8, 2006 can you kindly exsplain this in easy terms cheers then solved thank you so much.COUNT_RECURSIVE Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43180 Share on other sites More sharing options...
wisewood Posted June 8, 2006 Share Posted June 8, 2006 COUNT_RECURSIVE is an optional component of the count() function.if you were to use count($mess) and mess contained two arrays, the result would be 2.However, by using count($mess, COUNT_RECURSIVE) you end up with it counting the contents of the $mess array, as well as the contents of any arrays stored within mess.To be honest, in this case, i dont think its required, but i used it anyway. Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43208 Share on other sites More sharing options...
jimbob26 Posted June 8, 2006 Share Posted June 8, 2006 Maybe everyone has gone a little offtrack, all you need is a simple function called "in_array"ie:[code]$message = "Hello ()";$words=array("@","{","(","$","(","}","+");for($i=0;$i<strlen($message);$i++) { if(in_array($message[$i],$words)) { echo "$message.<br>sorry charecter used not allowed. <b>".$message[$i]." at position $i</b>"; }}[/code]Maybe thhat will help? Quote Link to comment https://forums.phpfreaks.com/topic/11477-stop-words-in-database-with-array-valadation/#findComment-43232 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.