3v4l.org

run code in 300+ PHP versions simultaneously
<?php function formatPhone($n) { //Remove any parentheses and the numbers they contain: $n = preg_replace("/\([0-9]+?\)/", "", $n); //Strip spaces and non-numeric characters: $n = preg_replace("/[^0-9]/", "", $n); //Strip out leading zeros: $n = ltrim($n, '0'); //Strip out leading +: $n = ltrim($n, '+'); if(strlen($n) <= 10) { if(substr( $n, 0, 2 ) === "39") return preg_replace('/^39/','+3939', $n); else return '+39' . $n; } else if(strlen($n) > 10){ return preg_replace('/^(?:\+?39|0)?/','+39', $n); }else return '+39' . $n; } echo formatPhone("335123456") . "\n"; echo formatPhone("39335123456") . "\n"; echo formatPhone("+39335123456") . "\n"; echo formatPhone("0039335123456") . "\n"; echo formatPhone("039335123456") . "\n"; echo formatPhone("3931234567") . "\n"; echo formatPhone("+39335123456") . "\n"; echo formatPhone("399123456") . "\n"; echo formatPhone("39399123456") . "\n"; echo formatPhone("+39399123456");
Output for git.master, git.master_jit, rfc.property-hooks
+39335123456 +39335123456 +39335123456 +39335123456 +39335123456 +393931234567 +39335123456 +39399123456 +39399123456 +39399123456

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