用空白替换双引号

时间:2014-10-22 22:17:30

标签: php json preg-replace str-replace double-quotes

所以我从JSON提要中收集数据并将其中的一些保存到数组中。这个特定项目$result['issuer']包含我们的客户'名。我猜这个名字可以包含任何
字符,但到目前为止,我只看到逗号(,),如: San Marino Unif Sch Dist,CA GO ......因为这个逗号< / strong>我正在使用json_encode但现在我似乎无法摆脱名称周围的双引号。我不确定我做错了什么,但尝试了很多不同的方法,没有任何运气:(

if($auction != false)
{   
  $auction = json_decode($auction, TRUE);

 foreach($auction['recent_results'] as $result)
 {
    // grab today's data for all auction types 
    if ($result['end_date'] === $GLOBALS["yesterday"]) 
    {
        $json_string = json_encode($result['issuer']);
        //$json_string = $result['issuer'];
        //$json_string = str_replace('/"([^"]+)"\s*:\s*/', '$1:', $json_string);
        $json_string = str_replace("\"", "", $json_string);
        //$json_string = str_replace(array('\'', '"'), '', $json_string);

        //$json_string = preg_replace("/[^a-zA-Z0-9 ,]+/", "", html_entity_decode($result['issuer'])); //this one kind of works, but not letting me escape the COMMA at the end
        //$json_string = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', $json_string);

        $pastAuction[] = array("ISSUER" => $json_string, "TYPE" => $result['issue_type'], "TERM" => $result['term'], "FINAL YIELD" => $result['closing_yield']."%", "CLOSING DATE" => $result['end_date']);         
    }
  }
}

现在名称将被保存为......

  • "San Marino Unif Sch Dist, CA GO"
  • 或在San Marino Unif Sch Dist&amp;等2个不同的字段中CA GO

但我想保存它:San Marino Unif Sch Dist, CA GO 请帮忙!!!

0 个答案:

没有答案