Gnziet Gnziet - 3 months ago 24
JSON Question

file get content with json not working

www.youtubeinmp3.com/fetch/?format=JSON&video=http://www.youtube.com/watch?v=i62Zjga8JOM


example output :

{

"title":"Happy Forever Alone Day (Forever Alone Song)",
"length":"125",
"link":"http:\/\/youtubeinmp3.com\/download\/get\ /?i=k1MakL%2FYlh6KUtEHqyQlg9XwtUUWO"

}


i want to get this using php json file get content but this is not working.

<?php
$json_url = "www.youtubeinmp3.com/fetch/?format=JSON&video=http://www.youtube.com/watch?v=i62Zjga8JOM";
$json = file_get_contents($json_url);
$data = json_decode($json, TRUE);
echo "<pre>";
print_r($data);
echo "</pre>";
?>


but nothing working please help me ..
$json_url = "www.youtubeinmp3.com/fetch/?format=JSON&video=$videoid";
$videoid is dyanamic value getting using post variable .

likie as

<?php
$video=$_POST['yturl'];
echo $video;?>


thanks.

Answer

Using this code to get your output.

$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, 'www.youtubeinmp3.com/fetch/?format=JSON&video=http://www.youtube.com/watch?v=i62Zjga8JOM&chof=json');
curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true);

$jsonData = json_decode(curl_exec($curlSession));
curl_close($curlSession);
echo "<pre>";
print_r($jsonData);
echo "</pre>"; 
Comments