- strpos: documentation ( source)
- ctype_alpha: documentation ( source)
<?php
$subject = "any";
$b = " ";
$delimited = "$b$subject$b";
$str = "Will *any* company do *any* job, (are there any)?";
echo "\nThe string: \"$str\"";
$temp = $str;
for ($i=0, $max = strlen($temp); $i < $max; $i++) {
if (!ctype_alpha($temp[$i]) ){
$temp[$i] = $b;
}
}
while ( ($pos = strpos($temp,$delimited)) !== false )
{
echo "\nThe subject \"$subject\" occurs at position ",($pos + 1);
for ($i=0,$max=$pos + 1 + strlen($subject); $i <= $max; $i++) {
$temp[$i] = $b;
}
}