3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function tag($str,$pos1,$pos2) { $offset=-1; $arrs=explode("-",$str); list($pos1,$pos2)=array(min($pos1,$pos2),max($pos1,$pos2)); foreach($arrs as &$chunk) { $len=strlen($chunk); if($offset+1>$pos2) break; if($offset+1<=$pos2 && $offset+$len>=$pos2) { $chunk=substr($chunk,0,$pos2-$offset-1)."<span style='color:red'>".substr($chunk,$pos2-$offset-1,1)."</span>".substr($chunk,$pos2-$offset); } if($offset+1<=$pos1 && $offset+$len>=$pos1) { $chunk=substr($chunk,0,$pos1-$offset-1)."<span style='color:red'>".substr($chunk,$pos1-$offset-1,1)."</span>".substr($chunk,$pos1-$offset); } $offset+=$len; } return $arrs; } print_r(tag("55798-45366-11255-48084-35644-28027-85391-45536-85002-55350-4166-5991-0313-3681-9382-9143-2852-8142-8643-0235-875-383-839-92-91-00-81",25,87)); ?>
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => 55798 [1] => 45366 [2] => 11255 [3] => 48084 [4] => 35644 [5] => <span style='color:red'>2</span>8027 [6] => 85391 [7] => 45536 [8] => 85002 [9] => 55350 [10] => 4166 [11] => 5991 [12] => 0313 [13] => 3681 [14] => 9382 [15] => 9143 [16] => 2852 [17] => 8142 [18] => 8643 [19] => 0<span style='color:red'>2</span>35 [20] => 875 [21] => 383 [22] => 839 [23] => 92 [24] => 91 [25] => 00 [26] => 81 )
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /in/Qe8S5 on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /in/Qe8S5 on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /in/Qe8S5 on line 7
Process exited with code 255.