网上只找到了下面的这个api...但试了一下...好像已经不能用了..现在你们都用什么方法来获取手机归属地等信息啊.....尽量不要下载号码段包
<?php
header("Content-Type:text/html;charset=utf-8");
if (isset($_GET['number'])) {
$url = 'http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo';
$number = $_GET['number'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "mobileCode={$number}&userId=");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$data = simplexml_load_string($data);
if (strpos($data, 'http://')) {
echo '手机号码格式错误!';
} else {
echo $data;
}
}
?><form action="mobile.php" method="get">
手机号: <input type="text" name="number" /> <input type="submit" value="提交" />
</form> 

解决方案 »

  1.   

    你发这个可以用嘛。
    http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode=13888888888&userid=
    返回:
    <string>13888888888:云南 昆明 云南移动合家欢卡</string>
      

  2.   

    这个API是可以用的,只是你的代码有问题:
    $data = simplexml_load_string($data);
    if (strpos($data, 'http://')) {
    // $data将变成一个对象类型变量,因而不能用于字符串函数 strpos,也不能被输出
    其实你大可不必用此方法,直接正则表达式或者字符串函数提取就可以。
      

  3.   

    php新手..不太会用...能解释一下吗..谢谢
      

  4.   

    <form action="mobile.php" method="get">
    给成你上面 php 代码所在的文件名
      

  5.   

    我是在一个HTML页面中传的表单这段代码另开了一个文件phone.php然后HTML页面中把表单action="phone.php"。这样没有错吧?
      

  6.   

    那你加载了 curl 扩展了吗?
      

  7.   

    开启了还是不行。Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\test\shouji.php:2) in C:\wamp\www\test\shouji.php on line 3
      

  8.   

    注释掉 header("Content-Type:text/html;charset=utf-8");//header("Content-Type:text/html;charset=utf-8");
      

  9.   

    我运行你的代码没用问题的哦,你打开php错误提示看看。
    php.ini中设置:
    display_errors=On
    error_reporting=E_ALL & ~E_NOTICE  重启apache再运行试试
      

  10.   

    还是空白页面。。我把两个文件的代码都贴给你看看。。这是HTML页面的<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <form id="form1" name="form1" method="post" action="shouji.php">
      <label for="number"></label>
      <input type="text" name="number" id="number" />
      <input type="submit" name="sumit" id="sumit" value="提交" />
    </form>
    </body>
    </html>
    这是shouji.php的<?php 
    //header("Content-Type:text/html;charset=utf-8"); 
    if (isset($_GET['number'])) { 
    $url = 'http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo'; 
    $number = $_GET['number']; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "mobileCode={$number}&userId="); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $data = curl_exec($ch); 
    curl_close($ch); 
    $data = simplexml_load_string($data); 
    if (strpos($data, 'http://')) { 
    echo '手机号码格式错误!'; 
    }
    else { 
    echo $data; 


    ?> 
      

  11.   

    <form id="form1" name="form1" method="post" action="shouji.php">改为<form id="form1" name="form1" method="get" action="shouji.php">
    一切就OK了
      

  12.   

    $url = 'http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo';
    $number = $_GET['number'];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "mobileCode={$number}&userId=");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $data = curl_exec($ch);
    curl_close($ch);
    $data = simplexml_load_string($data);
    上面这段代码是干什么的,有人能解释一下吗?
      

  13.   

    终于搞定了....但出来了乱码....于是我以为是这里字符集的问题
    把这里的字符集改成了GB2312...还是乱码..<?php 
    header("Content-Type:text/html;charset=utf-8"); 
      

  14.   

    使用编辑器把PHP文件本身的编码格式修改成utf-8应该就行了。
      

  15.   

    你上面那个不是,我说的是修改PHP文件的编码格式,必须用PHP编辑器修改。
      

  16.   

    在浏览器里修改编码是可以正常显示...我想知道怎么在php编辑器里修改..谢谢
      

  17.   

    header("Content-Type:text/html;charset=utf-8"); 好端端的,被你注释了。
      

  18.   

    我不知道你用的是什么编辑器,没法回答你。这样吧,你用记事本打开那个PHP文件,然后选择“另存为”,出现一个保存界面,在编码那一栏里面选择UTF-8,点击确定就行了。