3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = "this is a Test String to get the last index of word with an uppercase letter in PHP"; $pattern = "/.*\s([A-Z])(\w+)/"; //$pattern = "/.*\s([A-Z])[A-Z]+/"; preg_match($pattern, $str, $match); $letter = $match[1]; $word = $match[1] . $match[2]; $position = strrpos($str, $match[1].$match[2]); echo "Letter to find: " $letter . "\nWord to find: " . $word . "\nPosition of letter: " . $position;
based on pQZcp
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.7
Parse error: syntax error, unexpected '$letter' (T_VARIABLE), expecting ',' or ';' in /in/PuNJc on line 15
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /in/PuNJc:15 Stack trace: #0 {main}
Process exited with code 255.