I made this code
$message = 'This domain has strpos';
$links = array('domain.com', 'do.main');
$safe = strpos($message, $links);
return $message;
but got error errorHandler->error in my page, whats wrong with my code? did I do some missing code?
what I want just detect if the message have string in $links then do rest of my code
thanks for droping out
Please try this one will give expected output.
$message = 'This domain has strpos';
$links = array('domain.com', 'do.main');
$safe = array();
foreach($links as $key=>$result){
if(strpos($message, $result) != false){
$safe[$result] = "String is available";
} else{
$safe[$result] = "String is not available";
}
}
print_r($safe);
Since PHP has no elegant solution and all I see is full blown functions here's a simple one that will work
$arr will hold an array of string you do NOT want
// If string has illegal characters return false
function str_allowed($str, $arr) {
foreach ($arr as $bad_string) {
if(strpos($str, $bad_string) !== false)
return false; // bad string detected, return false
}
return true; // if we got this far means everything's good return true
}