Answers for "Check if array contains word in string"

0

Check if array contains word in string

$string = 'Hello, people at Stackoverflow';
$array = array('Hello', 'People');
$i = count(array_intersect($array, explode(" ", preg_replace("/[^A-Za-z0-9' -]/", "", $string))));
echo ($i) ? "found ($i)" : "not found";
Posted by: Guest on October-04-2021
0

array of string contains a part of a string search

if (yourArray.indexOf("someString") > -1) {
    //In the array!
} else {
    //Not in the array
}
Posted by: Guest on June-21-2021
0

check if string contains a value in array

$count = 0;
str_replace($owned_urls, '', $string, $count);
// if replace is successful means the array value is present(Match Found).
if ($count > 0) {
  echo "One of Array value is present in the string.";
}
Posted by: Guest on October-04-2021

Code answers related to "Check if array contains word in string"

Browse Popular Code Answers by Language