SimpleXMLElement error but xml is valid [closed]

2020-02-15 08:06发布

this is the error:

[01-Sep-2011 08:15:01] PHP Warning: SimpleXMLElement::__construct() [< a h ref='simplexmlelement.--construct'>simplexmlelement.--construct]: ../domain/feed-yself-tips.php:1: parser error : Start tag expected, '<' not found in /home/domain/public_html/mergedrss.php on line 135

[01-Sep-2011 08:15:01] PHP Warning: SimpleXMLElement::__construct() [< a h ref='simplexmlelement.--construct'>simplexmlelement.--construct]: 1f45 in /home/domain/public_html/mergedrss.php on line 135

[01-Sep-2011 08:15:01] PHP Warning: SimpleXMLElement::__construct() [< a h ref='simplexmlelement.--construct'>simplexmlelement.--construct]: ^ in /home/domain/public_html/mergedrss.php on line 135

[01-Sep-2011 08:15:01] PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/domain/public_html/mergedrss.php:135

Stack trace: #0 /home/domain/public_html/mergedrss.php(135): SimpleXMLElement->__construct('.../domain...', 0, true) #1 /home/domain/public_html/mergedrss.php(57): MergedRSS->__fetch_rss_from_url('.../domain...') #2 /home/domain/public_html/feed.php(21): MergedRSS->export(false, true, 15) #3 {main} thrown in /home/domain/public_html/mergedrss.php on line 135

标签: php simplexml
1条回答
爷、活的狠高调
2楼-- · 2020-02-15 08:48

The two most common things leading to this error if you are certain the xml is well formed are as follows.

A) Your feeding the simplexmlelement a filename instead of a string.

// For files/urls use the following.
// See: http://www.php.net/manual/en/function.simplexml-load-file.php
$xml = simplexml_load_file('example.xml');

// For xml strings use the following.
// See: http://www.php.net/manual/en/function.simplexml-load-file.php
$xml = simplexml_load_string($exmpleString);

B) The other common problem is that your trying to access a secured site (https://) and your copy of php doesnt have the openssl extension enabled in php.ini. See google for help on resolving this if it applies to you as the solution varies depending on whether your on a linux or windows server.

Without more information from you such as the source xml and code your using this is about all the help I can be.

Good luck :)

查看更多
登录 后发表回答