3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getAllWholeWordPos($s,$word){ $retval = false; $b = " "; for ($i=0, $max = strlen( $s ); $i < $max; $i++) { if ( !ctype_alpha( $s[$i] ) ){ $s[$i] = $b; } } while ( ( $pos = stripos( $s, $word) ) !== false ) { $retval[] = $pos; var_dump($word,$retval); for ( $i=0, $max = $pos + 1 + strlen( $word ); $i <= $max; $i++) { $s[$i] = $b; } } return [$retval,$s]; } $str = "TheraininSpainstaysmainlyintheplain."; $d = ["The", "rain", "in", "Spain","stays","mainly","plain"]; $arr = null; for ($i=0, $max = count($d); $i < $max; $i++) { list($r,$str) = getAllWholeWordPos($str,$d[$i]); if (is_array($r)) { foreach ($r as $key => $val) { $arr[$key] = $val; } } else { $arr[$r] = $d[$i]; } } var_dump($arr);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Automatic conversion of false to array is deprecated in /in/fYdNN on line 14 string(3) "The" array(1) { [0]=> int(0) } string(3) "The" array(2) { [0]=> int(0) [1]=> int(27) } Deprecated: Automatic conversion of false to array is deprecated in /in/fYdNN on line 14 string(2) "in" array(1) { [0]=> int(33) } array(2) { [0]=> string(5) "plain" [1]=> int(27) }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
61.44 ms | 402 KiB | 8 Q