douping1993 2014-05-24 23:27
浏览 67
已采纳

为什么我的.Explode()不能处理字符串[关闭]

I am trying to explode a string into a list based off comma's, I have done this before but for some reason this not working now.

Just for reference, the line where I called echo echo $members[6]; returns 2009, 7, 146, 277.00, Company 6 so I know everything is being stored properly into $members

I also know from calling $arrlength it returns the correct size of strings that I populate into $members.

So I have the right data and it is formatted correctly yet the ONLY lines that print on my index.php is the echo $members[6]; statement and since I have a VERY long scroll bar I am also guessing that echo "<br><br>"; prints too.

Any help would be greatly appreciated.

<html>
<head>
</head>
<body>

<?php
$str_data = file_get_contents("file.json");
$data = json_decode($str_data,true);

foreach ($data as $key => $value) 
{   
    foreach ($value as $k => $v) 
    { 
       $t = "";
        foreach ($v as $kk => $vv) 
        { 
             $t = $t . ", " . $vv;         
        }
        $members[] = substr($t, 2); //cuts out initial comma + space      
    }
}
$arrlength=count($members);

echo $members[6]; // returns 2009, 7, 146, 277.00, Company 6

for ($i=0; $i<$arrlength; $i++) 
{
     list($year, $rank, $revenue, $profit, $company) = explode(",", $members[i]);
     $year = trim($year);
     $rank = trim($rank);
     $revenue = trim($revenue);
     $profit = trim($profit);
     $company = trim($company);

     echo $year;
     echo $rank;
     echo $revenue;
     echo $profit;
     echo $company;
     echo "<br><br>";   
     }
?> 
</body>
</html>
  • 写回答

2条回答 默认 最新

  • duanjian9148 2014-05-24 23:35
    关注

    It does not work because you missed the $:

    explode(",", $members[i]);
    

    Should be:

    explode(",", $members[$i]);
    

    You should turn on errors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 爬取豆瓣电影相关处理
  • ¥15 手机淘宝抓清除消息接口
  • ¥15 C#无selenium
  • ¥15 LD衰减计算的结果过大
  • ¥15 用机器学习方法帮助保险公司预测哪些是欺诈行为
  • ¥15 计算300m以内的LD衰减
  • ¥15 数据爬取,python
  • ¥15 怎么看 cst中一个面的功率分布图,请说明详细步骤。类似下图
  • ¥15 为什么我的pycharm无法用pyqt6的QtWebEngine
  • ¥15 FOR循环语句显示查询超过300S错误怎么办