PHP正则式img、uni、yellow、name怎么取
http://g.qzone.qq.com/cgi-bin/friendshow/friendshow_font_recent_visitor?uin=123456
_Callback( {"Ishost":0, "items":[{"uin":625057555, "name":"⑨o诟╄→僦跩", "online":1, "yellow":-1, "time":1307710914, "img":"http://qlogo4.store.qq.com/qzone/625057555/625057555/50"}, {"uin":382351734, "name":"月亮之上", "online":1, "yellow":-1, "time":1307710914, "img":"http://qlogo3.store.qq.com/qzone/382351734/382351734/50"}, {"uin":282522062, "name":"兰博基尼盖拉多", "online":1, "yellow":-1, "time":1307710911, "img":"http://qlogo3.store.qq.com/qzone/282522062/282522062/50"}, {"uin":592238940, "name":"沵", "online":1, "yellow":-1, "time":1307710910, "img":"http://qlogo1.store.qq.com/qzone/592238940/592238940/50"}, {"uin":424270642, "name":"必 超", "online":1, "yellow":-1, "time":1307710906, "img":"http://qlogo3.store.qq.com/qzone/424270642/424270642/50"}, {"uin":552319084, "name":"Tramchen", "online":0, "yellow":3, "time":1307710905, "img":"http://qlogo1.store.qq.com/qzone/552319084/552319084/50"}, {"uin":1149017368, "name":"譕赖试ふ妖", "online":0, "yellow":-1, "time":1307710902, "img":"http://qlogo1.store.qq.com/qzone/1149017368/1149017368/50"}, {"uin":1084181406, "name":"爱&狠", "online":1, "yellow":-1, "time":1307710898, "img":"http://qlogo3.store.qq.com/qzone/1084181406/1084181406/50"}, {"uin":1228271644, "name":"一生随缘", "online":1, "yellow":-1, "time":1307710892, "img":"http://qlogo1.store.qq.com/qzone/1228271644/1228271644/50"}, {"uin":1396657178, "name":"鏦头开识 ", "online":1, "yellow":2, "time":1307710891, "img":"http://qlogo3.store.qq.com/qzone/1396657178/1396657178/50"}]});
追问:上传到服务器 测试可用,但是我的怎么是乱码了。。。
http://qlogo2.store.qq.com/qzone/25561741/25561741/5025561741
澶㈤毃鎯㈣当
0
-1
1307722247
http://qlogo2.store.qq.com/qzone/25561741/25561741/50
=====================
723408965
鎵句釜濂冲杩囧
0
-1
1307722246
答案:是JSON字符,可以直接用PHP的json_decode转换后直接调用
看代码:
$json = file_get_contents("http://g.qzone.qq.com/cgi-bin/friendshow/friendshow_font_recent_visitor?uin=123456");
$json = str_replace('_Callback(','',$json); //去掉_Callback(
$json = str_replace(');','',$json); //去掉);
$stdClass = json_decode($json); //转换数据
echo $stdClass->items[0]->img; //调用输出
//循环输出:
foreach($stdClass->items as $arr){
echo $arr->uin,'<br>';
echo $arr->name,'<br>';
echo $arr->online,'<br>';
echo $arr->yellow,'<br>';
echo $arr->time,'<br>';
echo $arr->img,'<br>';
echo '=====================','<br>';
}
//输出结果:
http://qlogo1.store.qq.com/qzone/28070984/28070984/50
28070984
小猪快跑
0
-1
1307721606
http://qlogo1.store.qq.com/qzone/28070984/28070984/50
=====================
528071823
♠
0
-1
1307721606
http://qlogo4.store.qq.com/qzone/528071823/528071823/50
=====================
419094066
sada0998
1
-1
1307721604
http://qlogo3.store.qq.com/qzone/419094066/419094066/50
=====================
445317667
梦‰相随…
1
-1
1307721598
http://qlogo4.store.qq.com/qzone/445317667/445317667/50
=====================
1007671203
若相守、卟离
1
-1
1307721595
http://qlogo4.store.qq.com/qzone/1007671203/1007671203/50
=====================
358627341
╰☆乱开杺
1
-1
1307721588
http://qlogo2.store.qq.com/qzone/358627341/358627341/50
=====================
954274504
私の心はばらばらですで
0
-1
1307721572
http://qlogo1.store.qq.com/qzone/954274504/954274504/50
=====================
184363404
伊人
0
-1
1307721570
http://qlogo1.store.qq.com/qzone/184363404/184363404/50
=====================
705288494
嗳じのve恋
0
-1
1307721570
http://qlogo3.store.qq.com/qzone/705288494/705288494/50
=====================
532257292
532257292
1
-1
1307721567
http://qlogo1.store.qq.com/qzone/532257292/532257292/50
=====================
其他:$str=file_get_contents($url);
preg_match("/\"name\":\"(.*?)\",\"online\"/sm",$str,$tmp1,PREG_SET_ORDER);
preg_match("/\"uni\":\"(.*?)\",\"yellow\"/sm",$str,$tmp2,PREG_SET_ORDER);
$name=$tmp1[1];
$uni=$tmp2[1]
上一个:PHP二级联动下拉选中,从数据库读取数据,修改页面时如何才能选中数据库中的值呢?
下一个:PHP怎样将输入的用户名和密码与存储在数据库的信息比较