外部循环未定义的变量?

时间:2012-06-20 19:53:03

标签: php mysql

这些变量在我的PHP代码开头定义:

$ftp_server = "";
$ftp_user_name = "";
$ftp_user_pass = "";
$AWS_ACCESS_KEY_ID = "";
$AWS_SECRET_ACCESS_KEY = "";
$base_url = "someurl?";

这是我使用变量的循环:

foreach( $contents as $fname )
{
    if (($fname != '.')  && ($fname != '..') )
        $url_params = array('Operation'=>"ItemLookup",
                            'Service'=>"AWSECommerceService",
                            'AWSAccessKeyId'=>$AWS_ACCESS_KEY_ID,
                            'AssociateTag'=>"",
                            'Version'=>"2011-08-01",
                            'Availability'=>"Available",
                            'ItemId'=>$fname,
                            'ItemPage'=>"1",
                            'ResponseGroup'=>"Large");

    $url_params['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
    $url_parts = array();
    foreach(array_keys($url_params) as $key)
        $url_parts[] = $key."=".$url_params[$key];
    sort($url_parts);
    $url_string = implode("&",$url_parts);
    $url = $base_url.$url_string;
    $ch = curl_init();                   //this part we set up curl 
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    $xml_response = curl_exec($ch);
    curl_close($ch);
    echo ($xml_response);
    //$xml = new SimpleXMLElement($xml_response);
    //$LargeImage = $xml->Items->Item->LargeImage->URL;
    //echo ($LargeImage);
    //echo "<option>{$fname}</option>\n";
}

但是我遇到了这些错误:

  

警告:SimpleXMLElement :: __ construct()
  [simplexmlelement .-- construct]:实体:第1行:解析器错误:开始   标签预期,'&lt;'

中找不到      

警告:SimpleXMLElement :: __ construct()
  [simplexmlelement .-- construct]:没有AWSAccessKeyId参数指定的

     

警告:SimpleXMLElement :: __ construct()
  [simplexmlelement .-- construct]:^

     

致命错误:未捕获的异常'异常',消息'字符串可以   在堆栈跟踪中不被解析为XML'#0
  SimpleXMLElement-&gt; __ construct('No AWSAccessKey ...')#1 {main}抛出   在

我认为所有这些错误都来自未定义的$ AWS_ACCESS_KEY_ID;但我确定了它,可能是什么问题?

这是$ xml_response回显:

  

否AWSAccessKeyId参数指定否AWSAccessKeyId参数   指定
  76786e9f-239F-4ad7-a2d7-9b89c7299f210.1040720000000000TrueASIN0072229713LargeAll0072229713http://www.amazon.com/The-Art-Java-Herbert(ECT   一个大字符串,因为它循环遍历所有文件)

什么是$ xml_response,当它被回显时它会显示整个字符串,但是当我尝试在xml中显示数据时,由于某种原因它会给我这些错误。

在回显$url之后,网址似乎被调用了两次http://url?Timestamp=2012-06-20T20:09:57.000Zhttp:url?Timestamp=2012-06-20T20:09:57.000Z

然后才正确循环

http://url?AWSAccessKeyId=&AssociateTag=&Availability=Available&ItemId=0072229713&ItemPage=1&Operation=ItemLookup&ResponseGroup=Large&Service=AWSECommerceService&Timestamp=2012-06-20T20:09:57.000Z&Version=2011-08-01
是什么让它在它之前称为2个网址?

0 个答案:

没有答案