PHP使移动验证字段

PHP使移动验证字段,php,html,Php,Html,我正在制作一个表单,其中有一个手机号码的输入字段,但我似乎无法让它正常工作。PHP代码获取IP和国家代码,然后列出要从中选择的选项。国家代码、旗帜和名称位于一个数组中: <?php $countries array(); $countries[] = array("code"=>"AF","name"=>"Afghanistan","d_code"=>"+93", "img"=>"https://checkmobi.com/static/images/flags/A

我正在制作一个表单,其中有一个手机号码的输入字段,但我似乎无法让它正常工作。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>';
?>


所以,这是一个代码示例,我想要的是复制类似于点击“Web演示”的内容,这里是手机号码字段。我想显示标志,然后是自动填充拨号代码的输入字段。任何指导或任何东西都会有所帮助。

我认为您没有正确创建国家/地区数组,请尝试以下方法:

$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")
);

你有什么问题?工作不正常是什么意思?问题在于没有创建阵列,阵列工作正常。它更多的是关于访问者将看到的表单,我希望表单与我链接的站点相似,有国旗,他们的代码等等。表单完全基于HTML和CSS,所以你可以通过它让它看起来像你想要的那样。你的问题具体是什么?或者你只是在问如何复制你在别人网站上看到的内容?因为在这一点上,你应该可以右键单击->查看源代码或检查它,看看它们是如何创建的。我尝试过这样做,但我似乎不明白,我不是很擅长html/css