小弟菜鸟,求高手回答我这个弱智问题 我怎么取得图中的那个值 刚接触这个,想边做边学,请指教,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $b=Tencent::api("friends/fanslist",array( "format" => "xml", "reqnum" => "20", "startindex" => "0", "mode" => "0", "install" => "0", "sex" => "0"),"get",false);print_r(json_decode($b,true));echo"<br>";echo"-------------------------------"; 是XML的 print_f结果:<root> <data> <curnum> 20 </curnum> <hasnext> 0 </hasnext> <info> <city_code> 29 </city_code> <country_code> 1 </country_code> <fansnum> 100 </fansnum> <head> http://app.qlogo.cn/mbloghead/ec086f8e8265338f812c </head> <https_head> https://app.qlogo.cn/mbloghead/ec086f8e8265338f812c </https_head> <idolnum> 247 </idolnum> <isfans> true </isfans> <isidol> true </isidol> <isrealname> 1 </isrealname> <isvip> 0 </isvip> <location> 中国 大理 </location> <name> shoujini00 </name> <nick> 倪旺达 </nick> <openid> DFEE460F0FD097462CFA8576D43E5B01 </openid> <province_code> 53 </province_code> <sex> 1 </sex> <tag/> <tweet> <from> 腾讯微博 </from> <id> 189275000692680 </id> <text> 克大理闲! </text> <timestamp> 1374646496 </timestamp> </tweet> </info> <info> <city_code> 4 </city_code> <country_code> 1 </country_code> <fansnum> 217 </fansnum> <head> http://app.qlogo.cn/mbloghead/b76a55db336bd8da47e2 </head> <https_head> https://app.qlogo.cn/mbloghead/b76a55db336bd8da47e2 </https_head> <idolnum> 198 </idolnum> <isfans> true </isfans> <isidol> true </isidol> <isrealname> 1 </isrealname> <isvip> 0 </isvip> <location> 中国 九江 </location> <name> o149484047 </name> <nick> 范泽鑫 </nick> <openid> 01B5A61F2AFEC00855A914AC44295092 </openid> <province_code> 36 </province_code> <sex> 1 </sex> <tag> <id> 3274154839212534452 </id> <name> 微博控 </name> </tag> <tag> <id> 5317943929679550835 </id> <name> 企鹅控 </name> </tag> <tag> <id> 6357215159807203124 </id> <name> Jay迷 </name> </tag> <tag> <id> 7209022255400351955 </id> <name> 我爱手机QQ浏览器 </name> </tag> <tag> <id> 8468239602781125813 </id> <name> 数码控 </name> </tag> <tag> <id> 8946946727085816901 </id> <name> 锋蜜 </name> </tag> <tag> <id> 10753364960634565058 </id> <name> 玉米 </name> </tag> <tag> <id> 15657928532735099976 </id> <name> 尊迷 </name> </tag> <tag> <id> 15932857217868104144 </id> <name> 凉粉 </name> </tag> <tag> <id> 17136297143514901751 </id> <name> Justin迷 </name> </tag> <tweet> <from> 腾讯微博 哦哦哦哦 是腾讯微博的个人信息API返回的数据啊如果是json的 就json_decode()就变成数组了,随便取值 xml的我居然不会.... 搭车学习..... http://www.nowamagic.net/librarys/veda/detail/793 搜了个方法 function xml_to_array( $xml ){ $reg = "/<(\\w+)[^>]*?>([\\x00-\\xFF]*?)<\\/\\1>/"; if(preg_match_all($reg, $xml, $matches)) { $count = count($matches[0]); $arr = array(); for($i = 0; $i < $count; $i++) { $key = $matches[1][$i]; $val = xml_to_array( $matches[2][$i] ); // 递归 if(array_key_exists($key, $arr)) { if(is_array($arr[$key])) { if(!array_key_exists(0,$arr[$key])) { $arr[$key] = array($arr[$key]); } }else{ $arr[$key] = array($arr[$key]); } $arr[$key][] = $val; }else{ $arr[$key] = $val; } } return $arr; }else{ return $xml; }}$str = '<root> <data> <curnum> 20 </curnum> <hasnext> 0 </hasnext> <info> <city_code> 29 </city_code> <country_code> 1 </country_code> <fansnum> 100 </fansnum> <head> http://app.qlogo.cn/mbloghead/ec086f8e8265338f812c </head> <https_head> https://app.qlogo.cn/mbloghead/ec086f8e8265338f812c </https_head> <idolnum> 247 </idolnum> <isfans> true </isfans> <isidol> true </isidol> <isrealname> 1 </isrealname> <isvip> 0 </isvip> <location> 中国 大理 </location> <name> shoujini00 </name> <nick> 倪旺达 </nick> <openid> DFEE460F0FD097462CFA8576D43E5B01 </openid> <province_code> 53 </province_code> <sex> 1 </sex> <tag/> <tweet> <from> 腾讯微博 </from> <id> 189275000692680 </id> <text> 克大理闲! </text> <timestamp> 1374646496 </timestamp> </tweet> </info> <info> <city_code> 4 </city_code> <country_code> 1 </country_code> <fansnum> 217 </fansnum> <head> http://app.qlogo.cn/mbloghead/b76a55db336bd8da47e2 </head> <https_head> https://app.qlogo.cn/mbloghead/b76a55db336bd8da47e2 </https_head> <idolnum> 198 </idolnum> <isfans> true </isfans> <isidol> true </isidol> <isrealname> 1 </isrealname> <isvip> 0 </isvip> <location> 中国 九江 </location> <name> o149484047 </name> <nick> 范泽鑫 </nick> <openid> 01B5A61F2AFEC00855A914AC44295092 </openid> <province_code> 36 </province_code> <sex> 1 </sex> <tag> <id> 3274154839212534452 </id> <name> 微博控 </name> </tag> <tag> <id> 5317943929679550835 </id> <name> 企鹅控 </name> </tag> <tag> <id> 6357215159807203124 </id> <name> Jay迷 </name> </tag> <tag> <id> 7209022255400351955 </id> <name> 我爱手机QQ浏览器 </name> </tag> <tag> <id> 8468239602781125813 </id> <name> 数码控 </name> </tag> <tag> <id> 8946946727085816901 </id> <name> 锋蜜 </name> </tag> <tag> <id> 10753364960634565058 </id> <name> 玉米 </name> </tag> <tag> <id> 15657928532735099976 </id> <name> 尊迷 </name> </tag> <tag> <id> 15932857217868104144 </id> <name> 凉粉 </name> </tag> <tag> <id> 17136297143514901751 </id> <name> Justin迷 </name> </tag> <tweet> <from> 腾讯微博';print_r(xml_to_array($str));结果就是一个数组 就可以用了 这么多的xml解析工具不用。simplexml,xpath,xmlreader. 你直接使用json format格式多好,让api给你返回json格式的内容array( "format" => "json", 改程序碰到$arrays问题 关于oAuth认证的参数的疑问 再问问题,简单问题80分到手。 PHP可以从一个服务器向另外一个服务器传递表单么 asp版php......N多问题... 关于多语言版本的问题! PHPChina/Zend 天津群 官方QQ群 3713860 如何进行验证? 关于读取他人网页源代码的问题!在线等待! linux下php连接mysql的问题 mysql 联合主键? php 二维数组
array( "format" => "xml", "reqnum" => "20", "startindex" => "0", "mode" => "0", "install" => "0", "sex" => "0")
,"get",false);
print_r(json_decode($b,true));
echo"<br>";
echo"-------------------------------";
print_f结果:<root>
<data>
<curnum>
20
</curnum>
<hasnext>
0
</hasnext>
<info>
<city_code>
29
</city_code>
<country_code>
1
</country_code>
<fansnum>
100
</fansnum>
<head>
http://app.qlogo.cn/mbloghead/ec086f8e8265338f812c
</head>
<https_head>
https://app.qlogo.cn/mbloghead/ec086f8e8265338f812c
</https_head>
<idolnum>
247
</idolnum>
<isfans>
true
</isfans>
<isidol>
true
</isidol>
<isrealname>
1
</isrealname>
<isvip>
0
</isvip>
<location>
中国 大理
</location>
<name>
shoujini00
</name>
<nick>
倪旺达
</nick>
<openid>
DFEE460F0FD097462CFA8576D43E5B01
</openid>
<province_code>
53
</province_code>
<sex>
1
</sex>
<tag/>
<tweet>
<from>
腾讯微博
</from>
<id>
189275000692680
</id>
<text>
克大理闲!
</text>
<timestamp>
1374646496
</timestamp>
</tweet>
</info>
<info>
<city_code>
4
</city_code>
<country_code>
1
</country_code>
<fansnum>
217
</fansnum>
<head>
http://app.qlogo.cn/mbloghead/b76a55db336bd8da47e2
</head>
<https_head>
https://app.qlogo.cn/mbloghead/b76a55db336bd8da47e2
</https_head>
<idolnum>
198
</idolnum>
<isfans>
true
</isfans>
<isidol>
true
</isidol>
<isrealname>
1
</isrealname>
<isvip>
0
</isvip>
<location>
中国 九江
</location>
<name>
o149484047
</name>
<nick>
范泽鑫
</nick>
<openid>
01B5A61F2AFEC00855A914AC44295092
</openid>
<province_code>
36
</province_code>
<sex>
1
</sex>
<tag>
<id>
3274154839212534452
</id>
<name>
微博控
</name>
</tag>
<tag>
<id>
5317943929679550835
</id>
<name>
企鹅控
</name>
</tag>
<tag>
<id>
6357215159807203124
</id>
<name>
Jay迷
</name>
</tag>
<tag>
<id>
7209022255400351955
</id>
<name>
我爱手机QQ浏览器
</name>
</tag>
<tag>
<id>
8468239602781125813
</id>
<name>
数码控
</name>
</tag>
<tag>
<id>
8946946727085816901
</id>
<name>
锋蜜
</name>
</tag>
<tag>
<id>
10753364960634565058
</id>
<name>
玉米
</name>
</tag>
<tag>
<id>
15657928532735099976
</id>
<name>
尊迷
</name>
</tag>
<tag>
<id>
15932857217868104144
</id>
<name>
凉粉
</name>
</tag>
<tag>
<id>
17136297143514901751
</id>
<name>
Justin迷
</name>
</tag>
<tweet>
<from>
腾讯微博
function xml_to_array( $xml )
{
$reg = "/<(\\w+)[^>]*?>([\\x00-\\xFF]*?)<\\/\\1>/";
if(preg_match_all($reg, $xml, $matches))
{
$count = count($matches[0]);
$arr = array();
for($i = 0; $i < $count; $i++)
{
$key = $matches[1][$i];
$val = xml_to_array( $matches[2][$i] ); // 递归
if(array_key_exists($key, $arr))
{
if(is_array($arr[$key]))
{
if(!array_key_exists(0,$arr[$key]))
{
$arr[$key] = array($arr[$key]);
}
}else{
$arr[$key] = array($arr[$key]);
}
$arr[$key][] = $val;
}else{
$arr[$key] = $val;
}
}
return $arr;
}else{
return $xml;
}
}$str = '<root>
<data>
<curnum>
20
</curnum>
<hasnext>
0
</hasnext>
<info>
<city_code>
29
</city_code>
<country_code>
1
</country_code>
<fansnum>
100
</fansnum>
<head>
http://app.qlogo.cn/mbloghead/ec086f8e8265338f812c
</head>
<https_head>
https://app.qlogo.cn/mbloghead/ec086f8e8265338f812c
</https_head>
<idolnum>
247
</idolnum>
<isfans>
true
</isfans>
<isidol>
true
</isidol>
<isrealname>
1
</isrealname>
<isvip>
0
</isvip>
<location>
中国 大理
</location>
<name>
shoujini00
</name>
<nick>
倪旺达
</nick>
<openid>
DFEE460F0FD097462CFA8576D43E5B01
</openid>
<province_code>
53
</province_code>
<sex>
1
</sex>
<tag/>
<tweet>
<from>
腾讯微博
</from>
<id>
189275000692680
</id>
<text>
克大理闲!
</text>
<timestamp>
1374646496
</timestamp>
</tweet>
</info>
<info>
<city_code>
4
</city_code>
<country_code>
1
</country_code>
<fansnum>
217
</fansnum>
<head>
http://app.qlogo.cn/mbloghead/b76a55db336bd8da47e2
</head>
<https_head>
https://app.qlogo.cn/mbloghead/b76a55db336bd8da47e2
</https_head>
<idolnum>
198
</idolnum>
<isfans>
true
</isfans>
<isidol>
true
</isidol>
<isrealname>
1
</isrealname>
<isvip>
0
</isvip>
<location>
中国 九江
</location>
<name>
o149484047
</name>
<nick>
范泽鑫
</nick>
<openid>
01B5A61F2AFEC00855A914AC44295092
</openid>
<province_code>
36
</province_code>
<sex>
1
</sex>
<tag>
<id>
3274154839212534452
</id>
<name>
微博控
</name>
</tag>
<tag>
<id>
5317943929679550835
</id>
<name>
企鹅控
</name>
</tag>
<tag>
<id>
6357215159807203124
</id>
<name>
Jay迷
</name>
</tag>
<tag>
<id>
7209022255400351955
</id>
<name>
我爱手机QQ浏览器
</name>
</tag>
<tag>
<id>
8468239602781125813
</id>
<name>
数码控
</name>
</tag>
<tag>
<id>
8946946727085816901
</id>
<name>
锋蜜
</name>
</tag>
<tag>
<id>
10753364960634565058
</id>
<name>
玉米
</name>
</tag>
<tag>
<id>
15657928532735099976
</id>
<name>
尊迷
</name>
</tag>
<tag>
<id>
15932857217868104144
</id>
<name>
凉粉
</name>
</tag>
<tag>
<id>
17136297143514901751
</id>
<name>
Justin迷
</name>
</tag>
<tweet>
<from>
腾讯微博';
print_r(xml_to_array($str));结果就是一个数组 就可以用了
simplexml,xpath,xmlreader.