由於用戶從API輸入有不同的結果,因此我需要打印消息,指出沒有特定元素的結果並打印出其中的結果。例如,我想說,這個變量沒有結果:$ model = $ jfo - > engine-> valve-> timing; 這裏是我的代碼,因此遠低於這裏是鏈接到API: http://api.edmunds.com/api/vehicle/v2/vins/1GCGG25U261243927?fmt=json&api_key=2jwwaax2sc4kuq7vg7ud79rc如何將在PHP中發現的特定數據返回給JSON調用
<?php
//ini_set("display_errors",1);
//exit;
$datvin="";
$title="";
$posts="";
$mds="";
$model="";
if (isset($_POST['vin'])){
$datvin=trim($_POST['vin']);
$json_file = file_get_contents('http://api.edmunds.com/api/vehicle/v2/vins/'.$datvin.'?fmt=json&api_key=2jwwaax2sc4kuq7vg7ud79rc');
// convert the string to a json object
$jfo = json_decode($json_file);
if ($jfo != '' && $jfo !== null) {
// read the title value
$title = $jfo->make->name;
// copy the posts array to a php var
$posts = $jfo->make->id;
$mds = $jfo->years[0]->year;
$model = $jfo ->engine->valve->timing;
}else {
$model="not found";
}
}
?>
<form role="form" action="index.php" method="post">
<div class="form-group">
<label for="VIN" class="hidden-lg hidden-md">Enter your VIN</label>
<input type="text" class="form-control" id="VIN" name="vin" placeholder="Enter your VIN" required="required">
</div>
<button type="submit" class="btn btn-primary btn-centered"><i class="fa fa-search"></i> Test VIN</button>
</form>
<div><?php echo $model; ?></div>
這是什麼線迴歸「$模式= $ JFO - >引擎 - >閥 - >時間;」 ? – azdonald
我需要PHP腳本來打印沒有結果的行。 – fredcampbell