我知道这个问题已经被回答很多次了,但是我不知道为什么我得到这个错误:
注意:未定义变量:urlfilter在/home/mjburkel/public_html/allxxcars/wp-content/plugins/insert-php/includes/shortcodes/shortcode-php.php(52):第75行的eval()代码]
我知道这通常是如果尚未定义变量,但是我正在声明它,因此我不确定是什么问题。这是我的代码。.请注意,这是我要插入到Wordpress PHP代码段插件中的php代码...因此,不确定该插件是否正在插入一些奇怪的代码或可能无法正确阅读?
<?php /* Template Name: Completed W517 */
error_reporting(E_ALL); // Turn on all errors, warnings and notices for easier debugging
// API request variables
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1'; // URL to call
$version = '1.0.0'; // API version supported by your application
$appid = 'XXX'; // Replace with your own AppID
$globalid = 'EBAY-US'; // Global ID of the eBay site you want to search (e.g., EBAY-DE)
$query = 'ford mustang'; // You may want to supply your own query
$safequery = urlencode($query); // Make the query URL-friendly
$i = '0'; // Initialize the item filter index to 0
// Create a PHP array of the item filters you want to use in your request
$filterarray =
array(
array(
'name' => 'MaxPrice',
'value' => '1000000',
'paramName' => 'Currency',
'paramValue' => 'USD'),
array(
'name' => 'MinPrice',
'value' => '100',
'paramName' => 'Currency',
'paramValue' => 'USD'),
array(
'name' => 'SoldItemsOnly',
'value' => 'true'),
);
function CurrencyFormat($number)
{
$decimalplaces = 2;
$decimalcharacter = '.';
$thousandseparater = ',';
return number_format($number,$decimalplaces,$decimalcharacter,$thousandseparater);
}
// Generates an indexed URL snippet from the array of item filters
function buildURLArray ($filterarray) {
global $urlfilter="";
global $i="";
// Iterate through each filter in the array
foreach($filterarray as $itemfilter) {
// Iterate through each key in the filter
foreach ($itemfilter as $key =>$value) {
if(is_array($value)) {
foreach($value as $j => $content) { // Index the key for each value
$urlfilter .= "&itemFilter($i).$key($j)=$content";
}
}
else {
if($value != "") {
$urlfilter .= "&itemFilter($i).$key=$value";
}
}
}
$i++;
}
return "$urlfilter";
} // End of buildURLArray function
// Build the indexed item filter URL snippet
buildURLArray($filterarray);
// Construct the findItemsByKeywords HTTP GET call
$apicall = "$endpoint?";
$apicall .= "OPERATION-NAME=findCompletedItems";
$apicall .= "&SERVICE-VERSION=$version";
$apicall .= "&SECURITY-APPNAME=$appid";
$apicall .= "&GLOBAL-ID=$globalid";
$apicall .= "&keywords=$safequery";
$apicall .= "&categoryId=213";
$apicall .= "&paginationInput.entriesPerPage=20";
$apicall .= "$urlfilter";
// Load the call and capture the document returned by eBay API
$resp = simplexml_load_file($apicall);
// Check to see if the request was successful, else print an error
if ($resp->ack == "Success") {
$results = '';
// If the response was loaded, parse it and build links
foreach($resp->searchResult->item as $item) {
if ($item->pictureURLLarge) {
$pic = $item->pictureURLLarge;
} else {
$pic = $item->galleryURL;
}
$link = $item->viewItemURL;
$title = $item->title;
$price = $item->sellingStatus->convertedCurrentPrice;
$bids = $item->sellingStatus->bidCount;
$end = $item->listingInfo->endTime;
$fixed = date('M-d-Y', strtotime($end));
if(empty($bids)){
$bids = 0;
}
// For each SearchResultItem node, build a link and append it to $results
$results .= "<div class=\"item\"><div class=\"ui small image\"><a href=\"$link\" target=\"_blank\"><img height=\"200px\" width=\"130px\" src=\"$pic\"></a></div><div class=\"content\"><div class=\"header\"><a href=\"$link\" target=\"_blank\">$title</a></div><div class=\"meta\" style=\"margin-top:.1em\"><span class=\"price\"></span><div class=\"extra\">Sold Date: $fixed</div><div class=\"extra\"><button class=\"ui button\"><a href=\"$link\" target=\"_blank\"><b>Number of Bids:</b> $bids </a></button></div><div class=\"extra\"><a href=\"$link\" target=\"_blank\"><button class=\"ui orange button\">Sold Price: $$price</button></a></div><div class=\"description\"></div></div></div></div>";
}
}
// If the response does not indicate 'Success,' print an error
else {
$results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
$results .= "AppID for the Production environment.</h3>";
}
?>
您正在使用哪个版本的PHP?当您首先在$urlfilter
函数中声明buildURLArray()
时,实际上应该收到语法错误:
php:错误-意外的'=',期望为','或';'在标准输入代码中
因为在使用global
关键字调用变量后,您不应该定义该变量。
基本上,应该用以下内容替换函数的开头:
// Generates an indexed URL snippet from the array of item filters
function buildURLArray ($filterarray) {
global $urlfilter, $i; // Load global variables
//…
}
并且$urlfilter
应该在全局范围内定义,而不是在函数范围内定义。您可能只需将其放在$i = '0'; // Initialize the item filter index to 0