2017-02-14 5 views
0

私はラジオサービスIcecastを持っています。そして、私はトランスミッションのデータを取得する必要があります。リスナー、現在の曲などです。 情報はJsonファイル:私は必要なものhttp://213.5.176.74:8002/status-json.xsl は、リスナーのデータを格納する変数を作成することで、現在の曲、など 私はこれを行うことを試みた:私はこれを取得の上、私はコードを書くときJsonで変数PHPを作成する方法

<?php 
$url="http://213.5.176.74:8002/status-json.xsl"; 
// Initiate curl 
$ch = curl_init(); 
// Disable SSL verification 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
// Will return the response, if false it print the response 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
// Set the url 
curl_setopt($ch, CURLOPT_URL,$url); 
// Execute 
$result=curl_exec($ch); 
// Closing 
curl_close($ch); 

// Will dump a beauty json :3 
var_dump(json_decode($result, true)); 

を:

array(1) { ["icestats"]=> array(7) { ["admin"]=> string(19) "[email protected]" ["host"]=> string(9) "127.0.0.1" ["location"]=> string(5) "Earth" ["server_id"]=> string(13) "Icecast 2.4.3" ["server_start"]=> string(31) "Wed, 08 Feb 2017 19:16:01 +0000" ["server_start_iso8601"]=> string(24) "2017-02-08T19:16:01+0000" ["source"]=> array(13) { ["audio_info"]=> string(10) "bitrate=24" ["genre"]=> string(3) "POP" ["listener_peak"]=> int(1) ["listeners"]=> int(0) ["listenurl"]=> string(28) "http://127.0.0.1:8002/stream" ["server_description"]=> string(6) "(null)" ["server_name"]=> string(6) "AutoDJ" ["server_type"]=> string(10) "audio/mpeg" ["server_url"]=> string(19) "https://habbosk.com" ["stream_start"]=> string(31) "Wed, 08 Feb 2017 19:19:02 +0000" ["stream_start_iso8601"]=> string(24) "2017-02-08T19:19:02+0000" ["title"]=> string(21) "AKONs Lonely Lyrics" ["dummy"]=> NULL } } } 

probl私は以前のコンテンツで変数を作る方法を知らないので、私はラジオの統計を入れるウェブサイトでそれを使用します。 あなたの答えに感謝します。 私はスペイン語を話します。私はgoogle translateを使用します。

お挨拶。

答えて

0

あなたが持っているものをビルドする...あなたは近くにいる!

返されたネストされた配列から変数を解析するだけで済みます。ここで

はあなたの同じデータ変数で、ネストされた配列の関係を示すために分離:私たちは、変数が深い作業工程

array(1) { 
    ["icestats"]=> array(7) { 
     ["admin"]=> string(19) "[email protected]" ["host"]=> string(9) "127.0.0.1" ["location"]=> string(5) "Earth" ["server_id"]=> string(13) "Icecast 2.4.3" ["server_start"]=> string(31) "Wed, 08 Feb 2017 19:16:01 +0000" ["server_start_iso8601"]=> string(24) "2017-02-08T19:16:01+0000" 
     ["source"]=> array(13) { 
      ["audio_info"]=> string(10) "bitrate=24" ["genre"]=> string(3) "POP" ["listener_peak"]=> int(1) ["listeners"]=> int(0) ["listenurl"]=> string(28) "http://127.0.0.1:8002/stream" ["server_description"]=> string(6) "(null)" ["server_name"]=> string(6) "AutoDJ" ["server_type"]=> string(10) "audio/mpeg" ["server_url"]=> string(19) "https://habbosk.com" ["stream_start"]=> string(31) "Wed, 08 Feb 2017 19:19:02 +0000" ["stream_start_iso8601"]=> string(24) "2017-02-08T19:19:02+0000" ["title"]=> string(21) "AKONs Lonely Lyrics" ["dummy"]=> NULL 
     } 
    } 
} 

だからここにあなたの元のコードがある...

<?php 
$url="http://213.5.176.74:8002/status-json.xsl"; 
// Initiate curl 
$ch = curl_init(); 
// Disable SSL verification 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
// Will return the response, if false it print the response 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
// Set the url 
curl_setopt($ch, CURLOPT_URL,$url); 
// Execute 
$result=curl_exec($ch); 
// Closing 
curl_close($ch); 

そして、ここに

$result = json_decode($result, true); /* UPDATED */ 

$stats = $result['icestats']; 
echo 'Admin is: ' . $stats['admin']; 
echo 'Server ID is: ' . $stats['server_id']; 

// and deeper 
$source = $stats['source']; 
echo 'Genre is: ' . $source['genre']; 
echo 'Song Title is: ' . $source['title']; 
+0

私にはうまくいかない:(私にこの結果を教えてください:管理者は{サーバーIDは{ジャンルは:{曲T Itle is:{ –

+0

@RodneyAraúzあなたの行を残して申し訳ありません '$ result = json_decode($ result、true);'上記を参照してください –

+0

ありがとうございました。それは素晴らしい出てきました!私はすでにこれを学んだので、私はもう問題はない –

関連する問題