上次我在這裏發表的問題,我被要求不要問有關獲取特定的軟件來工作的問題,而是更廣泛的編程問題API ...PHP代碼不工作
這麼說,我也找到了一些在線PHP代碼似乎符合我的需求。我正在運行一個腳本,需要一個php & tpl文件來創建一個新頁面。將這些代碼放在一個新的PHP文件中會導致某些內容被破壞。除了創建這個新的PHP文件和一個同名的空白TPL文件之外,我沒有做任何其他與集成此API有關的內容。
以下是PHP文件的示例。我完全錯過了一些小圖或大圖嗎?只是試圖創建一個簡單的網頁,在某些城市有交易。
<?
$key = ‘entercodehere’;
$search = 「http://api.yipit.com/v1/deals/?key=$key&division=indianapolis」;
$search_init = curl_init();
curl_setopt($search_init, CURLOPT_HTTPHEADER, array(‘Expect:’));
curl_setopt($search_init, CURLOPT_URL, $search);
curl_setopt($search_init, CURLOPT_RETURNTRANSFER, TRUE);
$yipit = curl_exec($search_init);
$obj = json_decode($yipit,true);
$cnt=count($obj["response"]["deals"]);
for($i=0;$i<$cnt;$i++)
{
echo 「<p>ID: 「.$obj["response"]["deals"][$i]["id"].」<br>Date Added: 「.$obj["response"]["deals"][$i]["date_added"].」<br>End Date: 「.$obj["response"]["deals"][$i]["end_date"].」<br>Discount formatted: 「.$obj["response"]["deals"][$i]["discount"]["formatted"].」<br>Price formatted: 「.$obj["response"]["deals"][$i]["price"]["formatted"].」<br>Value formatted: 「.$obj["response"]["deals"][$i]["value"]["formatted"].」<br>Purchased: 「.$obj["response"]["deals"][$i]["purchased"].」<br>Yipit title: 「.$obj["response"]["deals"][$i]["yipit_title"].」<br>Url: 「. $obj["response"]["deals"][$i]["url"].」<br>Yipit url: 「.$obj["response"]["deals"][$i]["yipit_url"].」<br>Mobile url: 「.$obj["response"]["deals"][$i]["mobile_url"].」<br>Image big: 「.$obj["response"]["deals"][$i]["images"]["image_big"].」<br>Image small: 「.$obj["response"]["deals"][$i]["images"]["image_small"].」<br>Tag name: 「.$obj["response"]["deals"][$i]["tags"][0]["name"].」<br>Tag slug: 「.$obj["response"]["deals"][$i]["tags"][0]["slug"].」<br>Tag url: 「.$obj["response"]["deals"][$i]["tags"][0]["url"].」<br>Business name: 「.$obj["response"]["deals"][$i]["business"]["name"].」<br>Source name: 「.$obj["response"]["deals"][$i]["source"]["name"].」</p>」;
}
?>
按照要求,我得到這個錯誤:服務器錯誤 在檢索[URL]該網站遇到錯誤。它可能因維護而關閉或配置不正確。 以下是一些建議: 稍後重新加載此網頁。 HTTP錯誤500(內部服務器錯誤):服務器試圖完成請求時遇到意外情況。
*「它不工作」 *和「造成的東西打破」 [不說明問題(http://stuck.include-once.org/#幫助3)就夠了。您需要詳細說明您的輸入,預期結果和實際結果,或詳細說明錯誤消息。 – mario
如果這是關於語法錯誤,請首先修復傾斜的引號。 – mario
第一行不應該說<?php而不是<? – bumperbox