3v4l.org

run code in 300+ PHP versions simultaneously
<?php $title = "服务员"; $term = array("服务","服务员"); $termKey = explode(',' , $term); $tempTitle = ''; $strlength = strlen($title); if($title && !empty($termKey) && is_array($termKey)){ $newTitle = $title; $cur = count($termKey) - 1; //倒叙匹配 for($i=$cur;$i >= 0 ;--$i) { if($termKey[$i] && strstr($newTitle , $termKey[$i])) { $position = mb_strrpos($newTitle,'</span>'); if($position){ $tempTitle .= mb_substr($newTitle , 0 , $position , 'UTF-8'); } $str = '<span class="fc-red">'.$termKey[$i].'</span>'; $newTitle = preg_replace("/$termKey[$i]/i" , $str , mb_substr($newTitle , $position , $strlength , 'UTF-8'),1); } } $newTitle = $tempTitle.$newTitle; echo $newTitle; }else echo $title; }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.32
Parse error: syntax error, unexpected '}' in /in/qANEa on line 24
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '}' in /in/qANEa on line 24
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/qANEa on line 24
Process exited with code 255.

preferences:
222.08 ms | 1395 KiB | 123 Q