3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function tryGetPhoneNumber($input) { if (preg_match('/(?<phoneNumber>\d{3}-\d{3}-\d{4})/', $input, $match)) { return $match['phoneNumber']; } return false; } $value = tryGetPhoneNumber("I'm going to call 555-123-4567 tomorrow.", $phoneNumber); if (is_string($value)) { var_dump($value); } else { echo 'No phone number.'; }
Output for 5.2.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Undefined variable: phoneNumber in /in/QC3HP on line 9 string(12) "555-123-4567"
Output for 5.0.4 - 5.2.1
Notice: Undefined variable: phoneNumber in /in/QC3HP on line 9 Warning: preg_match(): Compilation failed: unrecognized character after (?< at offset 3 in /in/QC3HP on line 4 No phone number.
Output for 4.3.11 - 4.4.5, 5.0.0 - 5.0.3
Notice: Undefined variable: phoneNumber in /in/QC3HP on line 9 Warning: preg_match(): Compilation failed: unrecognized character after (?< at offset 3 in /in/QC3HP on line 4 No phone number.
Output for 4.4.6 - 4.4.9
Notice: Undefined variable: phoneNumber in /in/QC3HP on line 9 string(12) "555-123-4567"
Output for 4.3.0 - 4.3.10
Notice: Undefined variable: phoneNumber in /in/QC3HP on line 9 Warning: Compilation failed: unrecognized character after (?< at offset 3 in /in/QC3HP on line 4 No phone number.