请参阅下面的代码:我试图在json_decode函数中传递一个名为$ search_term的变量,但它无效。我需要做什么?
$search_term = $this->input->post('search');
//echo $search_term; die();
$jsonArray = json_decode(file_get_contents('http://www.bloomapi.com/api/search?limit=10&offset=0&key1=practice_address.zip&op1=eq&value1='.$search_term),true);
print_r($jsonArray);
答案 0 :(得分:0)
我只是检查它是否正确我只是更改post方法以便我可以快速测试它。因为它可以正常工作然后它也可以使用post值。
$search_term = $this->input->get('search');
$jsonArray = json_decode(file_get_contents('http://www.bloomapi.com/api/search?limit=10&offset=0&key1=practice_address.zip&op1=eq&value1=' . $search_term), true);
print_r($jsonArray);
您需要重新检查$ search_term = $ this-> input-> post(' search');另外明智地遵循我的波纹指示进行适当的调试
$search_term = $this->input->post('search');
$api_url = 'http://www.bloomapi.com/api/search?limit=10&offset=0&key1=practice_address.zip&op1=eq&value1=' . $search_term;
echo $api_url;exit;
$jsonArray = json_decode(file_get_contents($api_url), true);
print_r($jsonArray);