PHP从列表中提取变量


PHP extracting variables from list

如何从以下列表中提取例如标题值?http://pastebin.com/11AiRCJh但是使用PHP,所以我可以将它保存到变量$newTitle中。

这里有一些代码:

$searchResultLink = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=$q&key=$key&maxResults=25";
$searchResultKod = file_get_contents($searchResultLink);
//echo $searchResultKod;
$json = json_decode($searchResultKod);
$title = $json->items[0]->snippet->title;
echo $title;

它是JSON格式的,所以在该字符串上使用json_decode()

$json = json_decode($your_string);
$title = $json->items[0]->snippet->title;

这将获得items列表中第一个项目的标题。

这是假设你已经有了这个字符串,如果这个信息在远程服务器/api上,你需要先使用file_get_contents()之类的东西来获取它。