megaman
megaman

Reputation: 163

PHP HTML Tags.and json_encode and json_decode. remove linebreaks in JSON

I have an array width an object which Iam trying to json_decode: My problem is that iam not sure how to make the right json_encoding and afterwords decode.

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

Decoding the [language_status] gives me:

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

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

which is fine, but my problem is that i can't seem to get an output when json decoding [infotext]. Iam sure it is because the html tags, but just cant get the right input/output the get this to work.

I would love to see the [infotext] output somewhere like this:

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

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

Please help me solve this

Ok i managed to recreate my problem and i found out its when i create the Json object the problem occurs: http://codepad.viper-7.com/SG175W

As you can see the JSon object has breaks in the array which is creating the problem. Any easy way to remove em?

Upvotes: 0

Views: 1823

Answers (2)

Chilion
Chilion

Reputation: 4490

This must work, maby you can change it in your way.

<?php

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

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

Upvotes: 1

bSaraogi
bSaraogi

Reputation: 148

Try this,

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

Upvotes: 2

Related Questions