Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
echo phoneClean2('+3488995657');
function phoneClean2($string)
{
$c1 = preg_replace("/[^\d+]/", "", $string);
if (strlen($c1) != 0) {
$cf = '';
if (strlen($c1) <= 10) {
$cf = '+39' . $c1;
} elseif ($c1[0] == '+' && strlen($c1) > 11) {
$cf = $c1;
} elseif (substr($c1,0,2) == '00') {
$cf = str_replace('00' , '+', $c1);
} else {
$cf = "+" . $c1;
}
if (substr($cf, 0, 2) == "++") {
$cf = substr_replace($cf, '+', 0, 2);
}
}
return ($cf != '') ? $cf : $string . '.KO';
}