我正在尝试使用PHP搜索JSON并使用HTML表单中给出的值。我让用户输入他们想要搜索的人的姓名,我希望它通过JSON查看他们的名字。
JSON示例:
{"responseData": {"total": 1775, "results": [{"wiki": "A._C._Grayling", "url": "/thinker/3118", "sep_dir": "", "label": "A. C. Grayling", "type": "thinker", "ID": 3118}
PHP代码:
$submit_value = $_POST['regular_philo'];
function searchinPho_json($type, $id, $obj, $label, $submit_value){
global $philo;
$base = "https://inpho.cogs.indiana.edu";
$format = "json";
$url = $base. '/' . $type . '/' . $id . '.' . $format;
$data = @file_get_contents($url, o, null, null);
foreach($obj as $item) {
foreach($item as $philo) {
if(isset($philo->$label) && $philo->$label == $submit_value) {
return $philo;
}
}
}
return null;
}
$data = searchinPho_json('thinker', 'id');
$json = json_decode($data);
$url = $json->url;
$label = $json->label;
如何使用给定的名称进行搜索并输出特定搜索所需的ID?