找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
楼主: 玉藻前

PHP求助!

[复制链接]

283

主题

4444

回帖

9871

积分

论坛元老

积分
9871
发表于 2018-12-23 22:16:40 | 显示全部楼层

wwww961h 发表于 2018-12-23 22:24

变成了数组,就可以$b=json_decode($a,true);ID=$b['id'] 小写的['id'] id是数组下标,

大佬,我现在去掉了那些,但是用了
print_r(json_decode($rs,true));
之后,后面会多个1是怎么回事啊?

{"battle":[{"id":"4988318832","buser":"muddyriddl","intype":"AP deficiency","type":"JQ"},
{"id":"11423615469","buser":"17750973387","intype":"AP deficiency","type":"QP"}]}1
这样。如果删掉那一句就不会有最后的1...

function get_content($url, $cookie) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //读取cookie
    $rs = curl_exec($ch); //执行cURL抓取页面内容
    curl_close($ch);
    print_r(json_decode($rs,true));
回复

使用道具 举报

12

主题

53

回帖

156

积分

注册会员

积分
156
 楼主| 发表于 2018-12-23 22:09:00 | 显示全部楼层

wwww961h 发表于 2018-12-23 22:24

变成了数组,就可以$b=json_decode($a,true);ID=$b['id'] 小写的['id'] id是数组下标,

json_decode换成json_encode,结果后面多了个true!


什么鬼!
回复

使用道具 举报

12

主题

53

回帖

156

积分

注册会员

积分
156
 楼主| 发表于 2018-12-23 22:17:03 | 显示全部楼层
又一个爬虫大佬
回复

使用道具 举报

12

主题

53

回帖

156

积分

注册会员

积分
156
 楼主| 发表于 2018-12-23 22:13:00 | 显示全部楼层
"

并不是哈哈哈
回复

使用道具 举报

3

主题

17

回帖

55

积分

注册会员

积分
55
发表于 2018-12-23 22:13:35 | 显示全部楼层
// 将xml转换为数组
    public function xmlToArray($str)
    {
//        var_dump($str);
        $xml       = $str;//XML文件
        $objectxml = simplexml_load_string($xml);//将文件转换成 对象
        $xmljson   = json_encode($objectxml);//将对象转换个JSON
        $xmlarray  = json_decode($xmljson, true);//将json转换成数组
        return $xmlarray;
    }



送你一个我常用的函数吧~
回复

使用道具 举报

12

主题

53

回帖

156

积分

注册会员

积分
156
 楼主| 发表于 2018-12-23 22:10:00 | 显示全部楼层

ai0by 发表于 2018-12-24 13:11

// 将xml转换为数组
    public function xmlToArray($str)
    {

报错了…删了public就好了(但是内容好像没有变啊)
我想弄成
if(intype=="0"){ intype="等待执行"; }
if(intype=="AP is less than 40"){ intype="AP上限不足40"; }
这样的替换应该怎么写?
回复

使用道具 举报

4

主题

76

回帖

178

积分

注册会员

积分
178
发表于 2018-12-23 22:24:07 | 显示全部楼层
public报错是因未我这个函数之前写在class里面的。。。
至于你说的这个问题,函数返回值是一个数组,所以当你执行 xmlToArray($successstring); 时应该把这个函数的结果赋值给一个变量,例如:$res = xmlToArray($successstring);
然后判断时使用
if($res['intype']=="0"){ intype="等待执行"; }
if($res['intype']=="AP is less than 40"){ intype="AP上限不足40"; }
这样写即可~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Discuz! X

GMT+8, 2025-4-22 22:03 , Processed in 0.018207 second(s), 3 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表