doubeishuai6598 2015-11-30 22:16
浏览 14

PHP,使用以前HTML表单中的输入变量搜索JSON

I am trying to search through JSON with PHP with a value given in an HTML form. I have the user enter the name of who they would like to search and I want it to look through the JSON for the their name.

JSON Example:

    {"responseData": {"total": 1775, "results": [{"wiki": "A._C._Grayling", "url": "/thinker/3118", "sep_dir": "", "label": "A. C. Grayling", "type": "thinker", "ID": 3118}

PHP code:

    $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;

How can I get it to search through with the name given and output the ID needed for the specific search?

  • 写回答

0条回答 默认 最新

    报告相同问题?