@ 2017-06-14T19:50:47Z <?php
function getAllWholeWordPos($s,$word){
$b = " ";
$delimited = "$b$word$b";
$retval = false;
for ($i=0, $max = strlen( $s ); $i < $max; $i++) {
if ( !ctype_alpha( $s[$i] ) ){
$s[$i] = $b;
}
}
while ( ( $pos = stripos( $s, $delimited) ) !== false ) {
$retval[] = $pos + 1;
for ( $i=0, $max = $pos + 1 + strlen( $word ); $i <= $max; $i++) {
$s[$i] = $b;
}
}
return $retval;
}
$whole_word = "any";
$str = "Will *$whole_word* company do *$whole_word* job, (are there $whole_word)?";
echo "\nString: \"$str\"";
$result = getAllWholeWordPos( $str, $whole_word );
$times = count( $result );
echo "\n\nThe word \"$whole_word\" occurs $times times:\n";
foreach ($result as $pos) {
echo "\nPosition: ",$pos;
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.30 , 8.2.0 - 8.2.24 , 8.3.0 - 8.3.12 String: "Will *any* company do *any* job, (are there any)?"
Deprecated: Automatic conversion of false to array is deprecated in /in/ZEoZe on line 15
The word "any" occurs 3 times:
Position: 6
Position: 23
Position: 44 Output for 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 String: "Will *any* company do *any* job, (are there any)?"
The word "any" occurs 3 times:
Position: 6
Position: 23
Position: 44 preferences:dark mode live preview
78.03 ms | 408 KiB | 5 Q