【问题标题】:Exploding string from a json从json爆炸字符串
【发布时间】:2014-01-27 15:51:11
【问题描述】:

所以,我的问题是:我从数据库中捕获数据,该日期的一部分在 json 数组中。然后,我将所有的 json 信息放入一个数组中。像这样:

foreach ($corporativos->lista as $value):
    $classe_row = '';

    $input = $value["info_adicionais"];
    $data = json_decode($input,true);
    echo $data['andamentos'];
    $arr1 = explode(',',$data['andamentos']);
  endforeach;

现在,我需要用这些信息填充一个表。但是我不能把字符串炸开。

字符串是这样的:

"name name name,123123/uf;name name,123123/uf"等。

【问题讨论】:

    标签: php json string explode implode


    【解决方案1】:

    首先修剪字符串并在“;”上爆炸并在“,”上签名为:

    $str = " Name name name, 123123/uf; Name name, 123123/uf ";
    $str = trim($str);
    $temp = explode(";",$str);
    if (count($temp) > 0) {
       foreach ($temp as $key=>$value) {
          $result[] = explode(",",$value);
          // OR
          $result[whatever the id you want here] = explode(",",$value);
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 2015-04-21
      相关资源
      最近更新 更多