【发布时间】:2017-11-20 11:27:49
【问题描述】:
正确输入时会在屏幕上打印,但输入错误时我不想做任何事情
我该怎么做?
<?php
header('Content-type: text/html; charset=utf8');
$api_key = 'local';
$keyword = 'test';
$url = 'test.json' . $api_key . '&' .'keyword' .'=' . $GLOBALS['q'] ;
$open = file_get_contents($url);
$data = json_decode($open, true);
$istatistikler = $data['data'];
if ($data) {
foreach ( $istatistikler as $istatistik ){
echo '<div class="right">';
echo 'Oyun modu: ' . $istatistik['title'] . '<br />' .
'Kazanma: ' . $istatistik['content'] . '<br />' .
'Kazanma: ' . $istatistik['image'] . '<br />' .
'Kazanma: ' . $istatistik['category'] . '<br />' .
'<br />' .
'<hr/>';
$karakter_simge = 'http://google.com' . $istatistik['image'] . '';
echo "<img src=".$karakter_simge." >" ;
echo '</div>';
}
}
?>
输出失败
警告: 文件获取内容(http://localhost/api/detail?X-Api-Key=local&keyword=a): 无法打开流:HTTP 请求失败! HTTP/1.1 406 不是 在线/opt/lampp/htdocs/weather-master/php/php-api.php 中可接受 10
“我不想打印失败”
感谢您的帮助!
【问题讨论】:
-
是的,我不想看到
-
您应该在您的 PHP 配置级别执行此操作。禁用错误显示,这是最佳实践。您应该检查您的日志是否有错误。
-
非常感谢您的回复!
标签: php json api if-statement foreach