Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

How can i split this string and get the url?

Hi, I am trying to split this string and get the url part. But i just cant figure it out... This is the code:

Code
{
   "data": {
      "url": "http://profile.ak.fbcdn.net/hprofile-ak-snc6/203526_2814507752871_15058207_s.jpg",
      "is_silhouette": false
   }
}

How can i do this, thank you
Just need some clarification...This whole code is the string?
(Apr 30, 2013 07:03 AM)Yani Wrote:  That code is JSON.

So lets get the url:
PHP Code

<?php 
$json 
= '{"data":{"url": "http://profile.ak.fbcdn.net/hprofile-ak-snc6/203526_2814507752871_15058207_s.jpg","is_silhouette": false}}';

$arr = json_decode($json);
$url = $arr[data][url];

echo 
$url; // http://profile.ak.fbcdn.net/hprofile-ak-snc6/203526_2814507752871_15058207_s.jpg 

You forgot the quotes around "data" and "url", that will throw an error in strict mode and shit will hit the fan if he ever actually uses constants with those names.

PHP Code

<?php 
$arr 
= json_decode($json);
$url = $arr['data']['url']; 
Hi guys, I resolved this earlier. But i appreciate helping out :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by DekoJul 21, 2014 07:49 AM 10 197 Jul 21, 2014 07:49 AM
Last Post: Deko
[PHP] by --Alexander--Apr 1, 2014 10:52 AM 3 143 Apr 1, 2014 10:52 AM
Last Post: --Alexander--
[PHP] by CPAManagerAug 19, 2013 05:05 AM 5 114 Aug 19, 2013 05:05 AM
Last Post: CPAManager