Click to See Complete Forum and Search --> : how to filter numbers in a string


themoon
08-05-2007, 12:27 PM
The following function filters any bad words in a string as illustrated below
How can adjust the funtion to make it able to filter an int out of string....


<?php
function Filter(&$text, $replace) {
//fill this array with the bad words you want to filter and their replacements
$bads = array (
array("Fool","F**l"),
array("you","u"),
array("email","eee"),
array("at","***"),
array("@","***"),
array("crap","c***")
);

if($replace==1) {
//we are replacing
$remember = $text;
for($i=0;$i<sizeof($bads);$i++) {
//go through each bad word
$text = eregi_replace($bads[$i][0],$bads[$i][1],$text); //replace it
}

if($remember!=$text) return 1; //if there are any changes, return 1


} else {
//we are just checking
for($i=0;$i<sizeof($bads);$i++) {
//go through each bad word
if(eregi($bads[$i][0],$text)) return 1; //if we find any, return 1
}

}
}


// This will replace all bad words with their replacements.$any is 1 if it found any
$wordsToFilter = "Hi, this is my mobile: 002134567891";
$result = Filter($wordsToFilter,1);



//this will not repace any bad words but instead will only search for them. $any is 1 if it found any
$result = Filter($wordsToFilter,0);
echo "result = $result<br>$wordsToFilter";

?>


I just wanted to return 1 if it found any numbers or email address in the string .
Thanks
M

themoon
08-06-2007, 01:20 PM
anyone

:confused:

knowj
08-06-2007, 02:27 PM
if (eregi("[0-9]+", $var))
{
//do something
}

themoon
08-07-2007, 06:26 AM
Thanks alot knowj

It works now :)