我正在制作一个表格,其中有一个手机号码输入字段,但我似乎无法让它正常工作。 PHP 代码获取 IP 和国家代码,然后列出可供选择的选项。国家代码、国旗和名称在一个数组中:
<?php
$countries array();
$countries[] = array("code"=>"AF","name"=>"Afghanistan","d_code"=>"+93", "img"=>"https://checkmobi.com/static/images/flags/AF-32.png");
$countries[] = array("code"=>"AL","name"=>"Albania","d_code"=>"+355", "img"=>"https://checkmobi.com/static/images/flags/AL-32.png");
$countries[] = array("code"=>"DZ","name"=>"Algeria","d_code"=>"+213", "img"=>"https://checkmobi.com/static/images/flags/DZ-32.png");
$countries[] = array("code"=>"AS","name"=>"American Samoa","d_code"=>"+1", "img"=>"https://checkmobi.com/static/images/flags/AS-32.png");
$countries[] = array("code"=>"AD","name"=>"Andorra","d_code"=>"+376", "img"=>"https://checkmobi.com/static/images/flags/AD-32.png");
.
.
.
$ip = $_SERVER['REMOTE_ADDR'];
$json = file_get_contents("http://ipinfo.io/{$ip}");
$details = json_decode($json);
$country_code = $details->country;
echo '<select name="mobile_verification">';
foreach ($countries as $country){
echo '<option value="'.$country['d_code'].'">'.$country['name'].'</option>';
}
echo '</select>';
?>
所以,这是一个代码示例,我想要的是复制这样的东西 https://www.cognalys.com/#单击此处的“Web Demo”(手机号码字段)。我想显示标志,然后是自动填充拨号代码的输入字段。任何指导或任何事情都会有所帮助。
最佳答案
我认为您没有正确创建国家/地区数组,请尝试这样做:
$countries = array(
array("code"=>"AF","name"=>"Afghanistan","d_code"=>"+93", "img"=>"https://checkmobi.com/static/images/flags/AF-32.png"),
array("code"=>"AL","name"=>"Albania","d_code"=>"+355", "img"=>"https://checkmobi.com/static/images/flags/AL-32.png"),
array("code"=>"DZ","name"=>"Algeria","d_code"=>"+213", "img"=>"https://checkmobi.com/static/images/flags/DZ-32.png"),
array("code"=>"AS","name"=>"American Samoa","d_code"=>"+1", "img"=>"https://checkmobi.com/static/images/flags/AS-32.png"),
array("code"=>"AD","name"=>"Andorra","d_code"=>"+376", "img"=>"https://checkmobi.com/static/images/flags/AD-32.png")
);
关于PHP Make 手机验证字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34422822/