我想使用他们的API(严格地用PHP)从Flipkart获取产品详细信息。我想创建一个搜索栏,用户可以在其中输入任何“查询”,并且只显示来自Flipkart的相关搜索结果。我什么都不知道。
<form action="test.php" method="get">
<input type="text" name="searchdata">
<label for="searchdata">Search Product</label>
<input id="search" type="submit" value="Search">
</form>
<?php
// Get Web Page Data using URL
echo "Flipkart";
if(isset($_GET['searchdata'])){
$search= $_GET['searchdata'];
$search= strtolower($search);
//space to plus
$search=str_replace(" ","+",$search);
$web_page_data = file_get_contents("https://flipkart.com/search?q=".$search);
echo "Data Output of above link"."<br/>";
echo "--------------------------------"."<br/>";
// We need particular data from the page and not the whole content
$item_list =explode('<div class="items-wrap">', $web_page_data); //from entire web page it will split based on word <div class="items-wrap">
//Item list is an array so print_r
//print_r($item_list);
$request = "https://affiliate-api.flipkart.net/affiliate/api/yuganshch.json";
$response = file_get_contents($request);
$results = json_decode($response, TRUE);
foreach ($results['data'] as $key => $itemdata) {
$price = $itemdata['Best_Price'];
$product_link = $itemdata['Uri'];
echo $seller."<br/>".$price."<br/>".$product_link."<br/><br/>";
}
}
else {
echo "<p>No Product Found, Please Search Again</p>";
}
你可以帮我解决这个问题吗?它不起作用。在foreach()函数的参数中显示错误:
这是错误:
注意:未定义的索引:第70行的/Applications/XAMPP/xamppfiles/htdocs/testing/test.php中的数据
警告:在第70行的/Applications/XAMPP/xamppfiles/htdocs/testing/test.php中为foreach()提供的参数无效
第70行:foreach($ results ['data']为$ key =&gt; $ itemdata)
那么$ results ['data']应该被哪个变量替换?