3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test1 = '07511 111111'; $test2 = '+447511 111111'; $test3 = '+44 (0) 7511 111111'; //step 1 - reduce it to digits: preg_match_all('([\+]{0,1}[^\(\) ][0-9]+)', $test1, $digits); $digits = implode($digits[0]); var_dump($digits); //now for step 2.. start by removing +44 and replacing it with 0 if (substr($digits, 0, 3) == '+44') { $digits = str_replace('+44', '0', $digits); } var_dump(substr($digits, 3, 1)); var_dump(strlen($digits)); //by this point we should have just a UK-style number, but we must validate it: if ((substr($digits, 3, 1) > 3) && strlen($digits) == 11) { //valid UK mobile number! echo "valid UK mobile number $digits"; }
Output for git.master, git.master_jit, rfc.property-hooks
string(11) "07511111111" string(1) "1" int(11)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
37.69 ms | 401 KiB | 8 Q