Newbie question
i have following function:
function isadult($description)
{
$bad=/*comma separated bad words*/;
$bad=explode(",",$bad);
foreach($bad as $key)
{
if(eregi($key,$description))
{
return true;
}
}
return false;
}
if (isadult($description)) exit;
else
this function apply only to variable $description if i want apply this function also to variable $title how to modify function ?
and eregi is deprecated how to change eregi with preg_match ?
thanks
You can send both the
$descriptionand the$titlevariable to the function. The variable name provided in the function declaration is only refering to the variable name within the function scope, and not any variable names outside the function, even if they happen to be identical (as with$descriptionin your case).Try
if(isadult($title)) {and you will find that it will work.The value of the external variable
$titleis put into the function variable$description, and will be referred to as$descriptionwithin the function scope (between { and })Since you’re not doing any actual regular expression matching in your example, you could just as well replace
eregi()withstripos(),stristr()or similar…You should also define your bad words list as an array right away, instead of having php converting it.