php 解析器错误:应为开始标记,未找到“<”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20423902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:11:24  来源:igfitidea点击:

parser error : Start tag expected, '<' not found

phpxmlsimplexml

提问by nish

I am using PHP for the first time. I am using the php sample for uploading image on ebay sandbox. I am getting the following error on running the PHP file:

我是第一次使用 PHP。我正在使用 php 示例在 ebay 沙箱上上传图像。运行PHP文件时出现以下错误:

PHP Warning:  simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 69
PHP Warning:  simplexml_load_string(): HTTP/1.1 200 OK in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 69
PHP Warning:  simplexml_load_string(): ^ in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 69
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 92
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 93
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 93
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 94
PHP Notice:  Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 94

Relevant lines are:

相关线路是:

69. $respXmlObj = simplexml_load_string($respXmlStr);     // create SimpleXML object from string for easier parsing
                                                      // need SimpleXML library loaded for this

92. $ack        = $respXmlObj->Ack;
93. $picNameOut = $respXmlObj->SiteHostedPictureDetails->PictureName;
94. $picURL     = $respXmlObj->SiteHostedPictureDetails->FullURL;

What I can understand is the respXMLObj is not getting set properly. I have checked that simleXML support is enabled.

我能理解的是 respXMLObj 没有正确设置。我已检查是否启用了 simleXML 支持。

Could someone please help me debug this. Thanks

有人可以帮我调试这个。谢谢

回答by Bart Friederichs

The code you refer to has this line:

您引用的代码有这一行:

//curl_setopt($connection, CURLOPT_HEADER, 1 ); // Uncomment these for debugging

it seems like you uncommented these. This will result in getting the HTTP header in your response. Which is OK for debugging, but it will create an XML parse error in simplexml_load_string.

好像你取消了这些注释。这将导致在您的响应中获取 HTTP 标头。这对于调试来说是可以的,但它会在simplexml_load_string.

Either comment it out again or put 0as its value.

再次将0其注释掉或将其作为其值。

回答by Ruslan Novikov

In my case. I just removed the invisible character The BOMin the beginning of the XML file. How to do it - depends on your text editor.

就我而言。我刚刚删除了 XML 文件开头的不可见字符 BOM。怎么做 - 取决于你的文本编辑器。

回答by Danilo Bruno

$hasError = false;

if ( $resp == 'Internal Server Error' || empty($resp) )
{
    $hasError = true;
}

if ( ! $hasError )
{                      
    $aux    = !empty($resp) ? explode('???', $resp) : NULL;
    $temp   = utf8_decode(trim($aux[0]));               
    $xml    = simplexml_load_string($temp); 
}

回答by aland

Do a var_dump($respXmlStr);my guess is that this string is not valid XML.

做一个var_dump($respXmlStr);我的猜测是这个字符串不是有效的 XML。

As per the simplexml-load-string documentation, the first parameter is expected to be A well-formed XML string- http://php.net/manual/en/function.simplexml-load-string.php

根据 simplexml-load-string 文档,第一个参数应该是A well-formed XML string- http://php.net/manual/en/function.simplexml-load-string.php