I would use preg_grep and some other fancy things.
$string = "Apple is a big tech company!";
$search = 'Apple Logo a';
$pattern = '/\b('.str_replace(' ', '|', preg_quote($search, '/')).')\b/i';
$arr = preg_grep($pattern, explode(' ', $string));
print_r($arr);
Outputs
Array ( [0] => Apple [2] => a )
Test it online
https://3v4l.org/ugbdZ
I threw the a in there just to show off. As you can see it only matches a not company etc..
And as a bonus it will properly escape any Regex stuff in the search string...
Yay!
As a side note you could also use the same pattern with preg_match_all if you wish.
$string = "Apple is a big tech company!";
$search = 'Apple Logo a';
$pattern = '/\b('.str_replace(' ', '|', preg_quote($search, '/')).')\b/i';
$numMatch = preg_match_all($pattern,$string,$matches);
print_r($numMatch);
print_r($matches);
Outputs
2
Array (
[0] => Array (
[0] => Apple
[1] => a
)
[1] => Array (
[0] => Apple
[1] => a
)
)
Test it
https://3v4l.org/ZOlUV
The only real difference is you get a more complicated array (just use $matches[1]) and the count of the matches without counting said array.