-3

I don't find any way to resolve the following issue. My page is showing blank page.

My code

$s = '{"kind":"track","id":38140822,"created_at":"2012/02/28 19:52:55 +0000","user_id":10138280,"duration":206052,"commentable":true,"state":"finished","original_content_size":3297188,"last_modified":"2014/12/08 02:41:00 +0000","sharing":"public","tag_list":"","permalink":"jjefufcfzfdb","streamable":true,"embeddable_by":"all","downloadable":false,"purchase_url":null,"label_id":null,"purchase_title":null,"genre":"","title":"كيفك انت - فيروز","description":"غناء : فيروز \r\nكلمات : زياد الرحباني ","label_name":"","release":"","track_type":"","key_signature":"","isrc":"","video_url":null,"bpm":null,"release_year":null,"release_month":null,"release_day":null,"original_format":"mp3","license":"all-rights-reserved","uri":"https://api.soundcloud.com/tracks/38140822","user":{"id":10138280,"kind":"user","permalink":"ajassim","username":"Aj Assim","last_modified":"2014/12/03 11:21:20 +0000","uri":"https://api.soundcloud.com/users/10138280","permalink_url":"http://soundcloud.com/ajassim","avatar_url":"https://i1.sndcdn.com/avatars-000037250069-f7k40a-large.jpg"},"permalink_url":"http://soundcloud.com/ajassim/jjefufcfzfdb","artwork_url":"https://i1.sndcdn.com/artworks-000019131565-k8e2j1-large.jpg","waveform_url":"https://w1.sndcdn.com/HfpRLxTHxxOK_m.png","stream_url":"https://api.soundcloud.com/tracks/38140822/stream","playback_count":3438477,"download_count":100,"favoritings_count":82285,"comment_count":3027,"attachments_uri":"https://api.soundcloud.com/tracks/38140822/attachments","policy":"ALLOW"}';

$simplexml = simplexml_load_string($s);
var_dump($simplexml); //returns the actual structure

After enabling error reporting by use following line

error_reporting(E_ALL);

I got these errors

Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /code/b2ET3r on line 4

Warning: simplexml_load_string(): {"kind":"track","id":38140822,"created_at":"2012/02/28 19:52:55 +0000","user_id" in /code/b2ET3r on line 4

Warning: simplexml_load_string(): ^ in /code/b2ET3r on line 4
bool(false) PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /code/b2ET3r on line 4 PHP Warning: simplexml_load_string(): {"kind":"track","id":38140822,"created_at":"2012/02/28 19:52:55 +0000","user_id" in /code/b2ET3r on line 4 PHP Warning: simplexml_load_string(): ^ in /code/b2ET3r on line 4 
DJ MHA
  • 598
  • 3
  • 18
  • there is a manual for a reason: http://php.net/json_decode - and what you're having there is JSON not XML. – hakre Dec 22 '14 at 10:40

1 Answers1

3

Why you try to parse Json with simplexml?

Try json_decode

$array = json_decode($s, true);

http://php.net/manual/en/function.json-decode.php

To get title

$array = json_decode($s, true);
echo $array['title'];

or

$object = json_decode($s, false);
echo $object->title;
mleko
  • 11,650
  • 6
  • 50
  • 71
  • Thanks if i use json_decode then how can I get property of title as in my code `"title":"كيفك انت - فيروز"` I have tried `$source->{'title'}` but this does not work – DJ MHA Dec 09 '14 at 23:02
  • Thanks I got it. I was trying it as object but this is array now. Can i get json_decode in object format?? – DJ MHA Dec 09 '14 at 23:04
  • I edited my answer to show both formats – mleko Dec 09 '14 at 23:05