网上只找到了下面的这个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>
<?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>
解决方案 »
- 关于php网站优化的问题
- php 中static public 与public static有区别吗?
- php乱码的问题,但google.cn不乱码,奇怪,急在线等待解决方案
- 小型MYSQL+PHP分页类库
- 求高手们帮帮忙.....看看我的这个问题
- 求一个日期递增语句
- 死的心都有了 Fatal error: Call to undefined function mysql_connect()
- 如何才能把查询出来的结果以数组的形式输出....
- 求一个mysql语句,谢谢
- linux下world writable 是什么权限?怎么设置啊?
- php curl函数登陆新浪微博
- 如何写一个后台管理权限?
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode=13888888888&userid=
返回:
<string>13888888888:云南 昆明 云南移动合家欢卡</string>
$data = simplexml_load_string($data);
if (strpos($data, 'http://')) {
// $data将变成一个对象类型变量,因而不能用于字符串函数 strpos,也不能被输出
其实你大可不必用此方法,直接正则表达式或者字符串函数提取就可以。
给成你上面 php 代码所在的文件名
php.ini中设置:
display_errors=On
error_reporting=E_ALL & ~E_NOTICE 重启apache再运行试试
<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;
}
}
?>
一切就OK了
$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);
上面这段代码是干什么的,有人能解释一下吗?
把这里的字符集改成了GB2312...还是乱码..<?php
header("Content-Type:text/html;charset=utf-8");