You can use str_replace function in PHP and add the elements to be replaced as an array. Otherwise you can use, of course, Regex (regular expression).
My solution:
<?php
$string = readline();
$search = readline();
$count = 0;
$string = str_replace([" ", ",", ".", "?", "!"], "@", $string);
$arr = explode("@", $string);
foreach ($arr as $item) {
if ($item == $search) {
$count++;
}
}
echo $count;