/    Sign up×
Community /Pin to ProfileBookmark

how to filter numbers in a string

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….

[code=php]
<?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”;

?>
[/code]

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

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@themoonauthorAug 06.2007 — anyone

?
Copy linkTweet thisAlerts:
@knowjAug 06.2007 — [code=php]
if (eregi("[0-9]+", $var))
{
//do something
}
[/code]
Copy linkTweet thisAlerts:
@themoonauthorAug 07.2007 — Thanks alot knowj

It works now ?
×

Success!

Help @themoon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...