3v4l.org

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