3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = [ '797734809', '0797734809', '27797734809', '0027797734809', '+27797734809', ]; function formatPhoneNo($no) { switch (true) { case (preg_match('#^7\d{8}$#', $no)): $no = '+27' . $no; break; case (preg_match('#^07\d{8}$#', $no)): $no = '+27' . substr($no, 1); break; case (preg_match('#^277\d{8}$#', $no)): $no = '+' . $no; break; case (preg_match('#^00277\d{8}$#', $no)): $no = '+' . substr($no, 2); break; case (preg_match('#^\+277\d{8}$#', $no)): break; default: throw new InvalidArgumentException('Invalid format supplied'); break; } return $no; } foreach ($x as $y) { echo formatPhoneNo($y) . "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
+27797734809 +27797734809 +27797734809 +27797734809 +27797734809

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:
155.71 ms | 405 KiB | 5 Q