我是php的新手,我想格式化手机号码......事情是我有一个包含拨号代码的下拉框,我有另一个用户输入他/她手机号码的盒子。我想做以下事情......
这是我的代码......似乎工作正常,但如果用户输入以' 0'
开头的数字,它会以某种方式删除最后一位数字 server {
listen 80;
server_name localhost;
root html;
index index.html index.htm index.php;
location = / {
return 302 /v1/;
}
error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
答案 0 :(得分:1)
$phNo = $_POST['RegPhone'];
$phNo = str_replace("+", "", $phNo); // Find + and replace if present
if (strpos($ph, '0') == 0) { // check if 0 found and it at first postition
$phNo = ltrim($phNo, '0');
}
if (substr($phNo, 0, strlen($_POST['RegDialCode'])) == $_POST['RegDialCode']) {
$phNo = ltrim($phNo, $_POST['RegDialCode']);
}
$phNo = $_POST['RegDialCode']. $phNo;