PHP HTML Tags.and json_encode和json_decode。删除JSON中的换行符

时间:2014-11-18 12:07:25

标签: php html json

我有一个数组宽度是一个对象,我试图json_decode:我的问题是,我不知道如何正确的json_encoding和后解码。

  Array (
    [id] => 22
    [infotext] => {"2":"<p>da</p>
    ","3":"<p>en</p>
    "}
    [language_status] => {"2":{"status":"0"},"3"}
  )

解码[language_status]给了我:

 var_dump(json_decode($arr['language_status']))

 stdClass Object (
   [2] => stdClass Object ( 
      [status] => 0
    )
   [3] => stdClass Object ( 
      [status] => 0
    )
  )

这很好,但我的问题是,当json解码[infotext]时,我似乎无法获得输出。 我确定这是因为html标签,但只是无法获得正确的输入/输出才能使其工作。

我希望在这样的地方看到[infotext]输出:

 var_dump(json_decode($arr['infotext']))

 stdClass Object (
   [2] => <p>da</p>
   [3] => <p>en</p>
  )

请帮我解决这个问题

好的,我设法重新创建我的问题,我发现它在我创建Json对象时出现问题:http://codepad.viper-7.com/SG175W

正如您所看到的,JSon对象在创建问题的数组中有中断。 有什么简单的方法可以删除em?

2 个答案:

答案 0 :(得分:2)

试试这个,

var_dump(json_decode($arr['language_status']),true);

答案 1 :(得分:1)

这必须有效,也许你可以按照自己的方式改变它。

<?php

$infotext = json_decode('{"2":"<p>da</p>","3":"<p>en</p>"}');

foreach($infotext as $text){
echo $text;
}
?>