I have to extract strings from a xml file. One particular value has been generated using json enconding. Here is a exemple of what I can find:
<plus_details>
[["Neuf"],["Petite copropri\u00e9t\u00e9"],["Vue mer"]]
</plus_details>
I would like to extract the strings and display them inline and separated by commas, like this :
Neuf, Petite copropriété, Vue mer
I tried using json_decode function, but the only thing I can display is:
array(3) {
[0]=>
array(1) {
[0]=>
string(4) “Neuf”
}
[1]=>
array(1) {
[0]=>
string(20) “Petite copropriété”
}
[2]=>
array(1) {
[0]=>
string(7) “Vue mer”
}
}
Any help would be appreciated. Thanks.
Simple use a loop to go through your data. When you json_decode the string you provided us, you will end-up with an array like this :
Array
(
[0] => Array
(
[0] => Neuf
)
[1] => Array
(
[0] => Petite copropriété
)
[2] => Array
(
[0] => Vue mer
)
)
So in order to get your data you need to loop your array.
foreach(json_decode($json) as $data){
echo $data[0];
echo '<br>';
}
The output of the above code is:
Neuf
Petite copropriété
Vue mer