如何strpos在多个文本字符串

问题描述:

阵列或in_array我做了这个代码如何strpos在多个文本字符串

$message = 'This domain has strpos'; 
$links = array('domain.com', 'do.main'); 
$safe = strpos($message, $links); 
return $message; 

,但得到的错误errorHandler->在我的网页,什么是错我的代码错误? 我做了一些缺少的代码?

我如果消息中的链接$有串只想检测则滴速出

+0

strpos的第二个参数是一个字符串(或者可以转换为字符串的东西),而不是数组。 http://php.net/manual/en/function.strpos.php。你需要循环访问数组值(foreach)或使用array_walk或array_map。 http://php.net/manual/en/function.array-walk.php http://php.net/manual/en/function.array-map.php – Nic3500

请试试这个人会给预期的输出做我的代码休息

感谢。

$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); 
+0

我会用'if(strpos($ message ,$ result)!== false){...}',否则你正在测试这个字符串是否出现在'haystack'变量的开头,而不是它是否存在。请参阅php.net关于评估带有strpos的布尔值的评论。 – fred2