我想显示最新版本的fontawesome版本。但是我对此有问题。我的脚本只显示空白页。请帮助我。
<?php
$url = 'https://data.jsdelivr.com/v1/package/gh/FortAwesome/Font-Awesome';
$data = file_get_contents($url);
$characters = json_encode($data);
echo $characters[0]->versions;
foreach ($characters as $character) {
echo $character->versions . '<br>';
}
?>
工作代码:
<?php
$url = 'https://data.jsdelivr.com/v1/package/gh/FortAwesome/Font-Awesome';
$data = file_get_contents($url);
//Use json_decode instead of json_encode
$characters = json_decode($data);
// Use var_dump or print_r to show an object
var_dump($characters->versions);
foreach ($characters->versions as $version) {
echo $version . '<br>';
}
除了混淆"编码"经文"解码"您可能还有另一个看不见的问题,因此请从以下内容的最低限度开始。
<?php
$url = 'https://data.jsdelivr.com/v1/package/gh/FortAwesome/Font-Awesome';
$data = file_get_contents($url);
var_dump(json_decode($data));
?>
我从中获得的结果的开始是:
object(stdClass)#1 (2) {
["tags"]=>
array(0) {
}
["versions"]=>
array(50) {
[0]=>
string(5) "5.9.0"
[1]=>
string(5) "5.8.2"
...
PHP版本信息:
php --version
PHP 7.3.6 (cli) (built: Jul 3 2019 20:46:48) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.6, Copyright (c) 1998-2018 Zend Technologies
可重现:
docker run --rm -i -t php bash
apt-get update && apt-get install -y vim
vim test.php
php test.php
启用了调试后,似乎您的主机的问题可能会发出网络(代理或类似(。
Warning: file_get_contents(...): failed to open stream: No route to host