[英]Get location from a stream url in PHP
I'm trying to get the redirect url from a stream using php. 我正在尝试使用php从流中获取重定向URL。
Here's the code I have right now: 这是我现在拥有的代码:
<?php
$stream = 'https://api.soundcloud.com/tracks/178525956/stream?client_id=XXXXXX';
$ch = curl_init($stream);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$url = curl_exec($ch);
echo $url;
curl_close($ch);
?>
Which outputs as a string: 输出为字符串:
{"status":"302 - Found","location":"THE_URL_I_WANT"}
So how ould I go about getting the url I want as a variable? 那么,我如何才能将我想要的网址作为变量? Thanks
谢谢
It's simple use json_decode
简单使用
json_decode
$data = json_decode($url);
$your_url = $data->location;
How about 怎么样
$data = json_decode($url);
$location = $data["location"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.