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?