[英]MySQL and PHP Microsoft Windows Error - Any idea what's happening?
[英]Unable to Access API Key with PHP…any idea what's up?
我是一名初级程序员。 最近,我一直在尝试用PHP开发。 我正在尝试创建有关国家的基本页面。 由于某些原因,我无法从此API页面获取信息。 谁能给我一些提示?
这是样本国家/地区数组的样子。 理想情况下,我想尝试获取“名称”属性。
这是我的HTML和PHP:
<?php
if(!empty($_GET['country'])) {
$country_url = 'https://restcountries.eu/rest/v1/name/' . urlencode($_GET['country']) . '?fullText=true';
$country_json = file_get_contents($country_url);
$country_array = json_decode($country_url, true);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset = "utf-8" />
<title> PHP Country Practice </title>
</head>
<body>
<form action="">
<input type = "text" name = "country" />
<button type="submit">submit </button>
</form>
<?php
if(!empty($country_array)) {
echo '<p> $country_array['name'] </p>';
}
?>
</body>
</html>
您将返回一个关联数组,因此请使用如下标识符:
$country_array[0]['name']
如果是对象,请使用以下代码。
echo $country_array[0]->name;
供阵列使用
echo $country_array[0]['name'];
index
,在本例中为0
。 {}
(tks AbraCadaver ),即: echo "<p> {$country_array[0]['name']} </p>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.