Search code examples
phparraysstringstrpos

how to strpos with array or in_array in multiple text string


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


Solution

  • 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);