3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ReformatPhoneNumber($number){ if( !preg_match('/^[0-9][0-9\- ]+[0-9]$/', $number) || // (strlen($number) > 12) || // (strlen($number) < 7) || (preg_match_all('/[0-9]/', $number) > 12 ) || (preg_match_all('/[0-9]/', $number) < 7 ) || (preg_match('/[ \-]{2,}/', $number)) ){ throw new \Exception('Invalid phone number'); } return trim(preg_replace('/[^0-9]/','',$number)); } echo ReformatPhoneNumber('012-345 69') ."\n"; foreach(array('012345', '-012345 678', '01203- 34566', '123456678875432','1234x567','1234567890123') as $invalid){ try { ReformatPhoneNumber($invalid); }catch(\Exception $e){ continue; } echo "ACCEPTED $invalid !!!!!!!!\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
01234569

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:
48.2 ms | 401 KiB | 8 Q