Curl not working in one server, but OK in all others - php

below code is not working on one server, but working fine in others. I am getting this error:
Warning: simplexml_load_string(): Entity: line 1: parser error : Opening and ending tag mismatch: HR line 1 and body in testchecker.php on line 11
Warning: simplexml_load_string(): dden.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.5.20</h3></body> in testchecker.php on line 11
Warning: simplexml_load_string(): ^ in testchecker.php on line 11
Warning: simplexml_load_string(): Entity: line 1: parser error : Opening and ending tag mismatch: HR line 1 and html in testchecker.php on line 11
Warning: simplexml_load_string(): Entity: line 1: parser error : Premature end of data in tag body line 1 in testchecker.php on line 11
Warning: simplexml_load_string(): Entity: line 1: parser error : Premature end of data in tag html line 1 in testchecker.php on line 11
Warning: Invalid argument supplied for foreach() in testchecker.php on line 12
<?php
set_time_limit(0);
$url="http://test";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($data);
foreach($xml->User as $child){
echo $child->Id."<br/>";
}
?>
I dont understand why this error is getting, because in local and other servers its working fine. On dreamhost, its not. Can anybody help me in this.

The error message already tells you, what is wrong
Warning: simplexml_load_string(): Entity: line 1: parser error : Opening and ending tag mismatch: HR line 1 and body in testchecker.php on line 11
Warning: simplexml_load_string(): dden.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.5.20</h3></body> in testchecker.php on line 11
XML requires all tags be closed, while with HTML, you can omit the closing tag occasionally.
In this case, you have a <hr> tag without a corresponding closing tag. This is perfectly valid in HTML. However, it is not well-formed XML, which is required by simplexml_load_string
Description
Takes a well-formed XML string and returns it as an object.

I have fixed the issue.
The ip was blocked, so forbidden message was getting, instead of xml.
Unblocking the ip fixed everything.

Related

How to get components from rss using php

I want to know to get components from rss using php.
I have created a php code, when I was running it on wampsever it was running well but when I ran it on my website this error was showing
PHP code is
<?php
$feeds = array('http://feeds.feedburner.com/ndtvnews-top-stories?format=xml');
foreach( $feeds as $feed ) {
$xml = simplexml_load_file($feed);
foreach($xml->channel->item as $item)
{
$date_format = "j-n-Y"; // 7-7-2008
$link = $item->link;
echo date($date_format,strtotime($item->pubDate));
echo ''.$item->title.'';
echo '<div>' . $item->description . '</div>';
}
}
?>
and Error is
PHP Error Message
Warning: simplexml_load_file() [function.simplexml-load-file]:
http://feeds.feedburner.com/ndtvnews-top-stories?format=xml:1: parser
error : Document is empty in /home/a7989425/public_html/rss.php on
line 5
PHP Error Message
Warning: simplexml_load_file() [function.simplexml-load-file]: in
/home/a7989425/public_html/rss.php on line 5
Free Web Hosting
PHP Error Message
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in
/home/a7989425/public_html/rss.php on line 5
PHP Error Message
Warning: simplexml_load_file() [function.simplexml-load-file]:
http://feeds.feedburner.com/ndtvnews-top-stories?format=xml:1: parser
error : Start tag expected, '<' not found in
/home/a7989425/public_html/rss.php on line 5
PHP Error Message
Warning: simplexml_load_file() [function.simplexml-load-file]: in
/home/a7989425/public_html/rss.php on line 5
PHP Error Message
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in
/home/a7989425/public_html/rss.php on line 5
PHP Error Message
Warning: Invalid argument supplied for foreach() in
/home/a7989425/public_html/rss.php on line 7
please help
thanks

PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found [duplicate]

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 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.
Could someone please help me debug this. Thanks
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.
Either comment it out again or put 0 as its value.
In my case. I just removed the invisible character The BOM in the beginning of the XML file. How to do it - depends on your text editor.
$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);
}
Do a var_dump($respXmlStr); my guess is that this string is not valid 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 XML error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I was testingsimplexml_load_string() func.
<?php
ini_set('display_errors', '1');
$test = stripslashes($_POST['xml']);
$testing = simplexml_load_string($test);
print_r($testing);
?>
After the execution following error occurred, even if i am striping slashes.
Warning: simplexml_load_string(): Entity: line 1: parser error : Malformed declaration expecting version in /var/www/check.php on line 5
Warning: simplexml_load_string(): <?xml encoding='utf8'?><!DOCTYPE a[<!ENTITY e SYSTEM '/etc/passwd'>]><a>&e;</a> in /var/www/check.php on line 5
Warning: simplexml_load_string(): ^ in /var/www/check.php on line 5
Warning: simplexml_load_string(): Entity: line 1: parser error : Blank needed here in /var/www/check.php on line 5
Warning: simplexml_load_string(): <?xml encoding='utf8'?><!DOCTYPE a[<!ENTITY e SYSTEM '/etc/passwd'>]><a>&e;</a> in /var/www/check.php on line 5
Warning: simplexml_load_string(): ^ in /var/www/check.php on line 5
Warning: simplexml_load_string(): Entity: line 1: parser error : Entity 'e' not defined in /var/www/check.php on line 5
Warning: simplexml_load_string(): <?xml encoding='utf8'?><!DOCTYPE a[<!ENTITY e SYSTEM '/etc/passwd'>]><a>&e;</a> in /var/www/check.php on line 5
Warning: simplexml_load_string(): ^ in /var/www/check.php on line 5
How i can solve this error ?
I think that xml file you are trying to convert has a bad format. You can try the example that there is in official doc here in the first example and then try to fit your XML file to be like that.

Artistdata.com RSS Feed parsing works locally but not on production server

I've been trying for the past couple of days to figure out why my code works perfectly locally but fails when deployed on a production server.
My local testing environment is the latest MAMP on a 10.7.2 Lion iMac.
Basically I need to fetch certain XML RSS data from Artistdata.com in order to insert it into a simple PHP-driven, non-CMS website I'm working on.
<!DOCTYPE html>
<html>
<head>
<title>RSS FEED Parser</title>
</head>
<body>
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
# RSS Feed parser #
function getFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
foreach ($x->show as $showEntry) {
echo '<div>';# date
$newDate = new DateTime($showEntry->date);
echo date_format($newDate, 'l, F j, Y');
echo '</div>';# /date
# further data fetching, totally unrelated
# to the problem that I'm experiencing
}
}
?>
<!-- START FEED PARSING -->
<div id="feed-data">
<?php getFeed('http://feeds.artistdata.com/xml.shows/artist/AR-30CA266E4BEDD78F/xml/future'); ?>
</div>
<!-- END FEED PARSING -->
</body>
</html>
I'm sure there are more people who had similar problems but I've yet to find a viable solution.
If you have any pointers I'd be very grateful.
EDIT: Forgot to post the errors, so here they are below
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Space required after the Public Identifier in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : SystemLiteral " or ' expected in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : SYSTEM or PUBLIC, the URI is missing in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 9: parser error : Opening and ending tag mismatch: hr line 7 and body in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </body></html> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 9: parser error : Opening and ending tag mismatch: body line 4 and html in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </body></html> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 10: parser error : Premature end of data in tag html line 2 in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/*****/public_html/ssr/parse-feed.php:17 Stack trace: #0 /home/*****/public_html/ssr/parse-feed.php(17): SimpleXMLElement->__construct('<!DOCTYPE HTML ...') #1 /home/*****/public_html/ssr/parse-feed.php(33): getFeed('http://feeds.ar...') #2 {main} thrown in /home/*****/public_html/ssr/parse-feed.php on line 17
Problem solved, I was using the wrong feed, the correct one is http://artistdata.sonicbids.com/john-latini/shows/xml/future
That XML does not look like RSS. It is an specific format defined by http://feeds.artistdata.com/_css/shows.xsd.
The error messages all say that you get an HTML (2.0) page not a XML. I can not reproduce that, I get the XML using file_get_contents().
Try to output the HTML page, maybe it has some more information.
echo file_get_contents('http://feeds.artistdata.com/xml.shows/artist/AR-30CA266E4BEDD78F/xml/future');

Errors from simplexml_load_file

I'm with several errors
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: /home/lineage/public_html/acp/xml/banners.xml:48: parser error : Opening and ending tag mismatch: banner line 33 and list in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: </list> in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: ^ in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: /home/lineage/public_html/acp/xml/banners.xml:48: parser error : Premature end of data in tag banner line 26 in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: </list> in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: ^ in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: /home/lineage/public_html/acp/xml/banners.xml:48: parser error : Premature end of data in tag banner line 19 in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: </list> in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: ^ in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: /home/lineage/public_html/acp/xml/banners.xml:48: parser error : Premature end of data in tag list line 2 in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: </list> in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: ^ in /home/lineage/public_html/acp/core.php on line 191
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Notice: Trying to get property of non-object in /home/lineage/public_html/acp/core.php on line 206
[23-Aug-2013 15:35:20 America/Sao_Paulo] PHP Warning: Invalid argument supplied for foreach() in /home/lineage/public_html/acp/core.php on line 197
I took this system ever made but it does not know what it is happening!
line: 197 core.php
foreach ($this->getAll() as $banner) {
line: 191 core.php
$_xmlBanners = simplexml_load_file(PATH_XML."banners.xml");
Baners.xml:
<?xml version="1.0" encoding="UTF-8"?>
<list>
<banner id="1">
<image>http://lineagefree.com/acp/images/l2jbr.png</image>
<link>http://l2j.lt/topai/balsuoti-7907.php</link>
<votes>
<link>http://l2j.lt/topai/mokamas-7907.php</link>
<regexp><div class='list_8' style="font-weight: bold">(.*)</div></regexp>
</votes>
</banner>
<banner id="2">
<image>http://lineagefree.com/acp/images/top100mmorpg.png</image>
<link>http://l2j.lt/topai/balsuoti-7907.php</link>
<votes>
<link>http://l2j.lt/topai/mokamas-7907.php</link>
<regexp><div class='dlist_8' style="font-weight: bold">(.*)</div></regexp>
</votes>
</banner>
<banner id="3">
<image>http://lineagefree.com/acp/images/gamesitestop100.jpg</image>
<link>http://l2j.lt/topai/balsuoti-7907.php</link>
<votes>
<link>http://l2j.lt/topai/mokamas-7907.php</link>
<regexp><div class='dlist_8' style="font-weight: bold">(.*)</div></regexp>
</votes>
<banner id="4">
<image>http://lineagefree.com/acp/images/arenatop100.png</image>
<link>http://l2j.lt/topai/balsuoti-7907.php</link>
<votes>
<link>http://l2j.lt/topai/mokamas-7907.php</link>
<regexp><div class='dlist_8' style="font-weight: bold">(.*)</div></regexp>
</votes>
<banner id="5">
<image>http://lineagefree.com/acp/images/mmorpglist.jpg</image>
<link>http://l2j.lt/topai/balsuoti-7907.php</link>
<votes>
<link>http://l2j.lt/topai/mokamas-7907.php</link>
<regexp><div class='dlist_8' style="font-weight: bold">(.*)</div></regexp>
</votes>
<banner id="6">
<image>http://lineagefree.com/acp/images/top200.gif</image>
<link>http://l2j.lt/topai/balsuoti-7907.php</link>
<votes>
<link>http://l2j.lt/topai/mokamas-7907.php</link>
<regexp><div class='dlist_8' style="font-weight: bold">(.*)</div></regexp>
</votes>
</banner>
</list>
follows all data. if you need any more please ask me.
I'm desperate.
Sorry my english. was done with google!
The error message Opening and ending tag mismatch: banner line 33 and list is telling you that while parsing the XML file, the parser found an opening tag <banner>, and then some nested content, but when it was expecting the matching end tag </banner> it found a different end tag, </list>.
This generally happens when you have a tag opened somewhere that you never close, meaning the parser is still waiting for you to close it when it gets to the close of some outer block.
In this case, you can look through your XML and see that there are 6 opening <banner> tags, but only 3 closing </banner>, so something's clearly gone wrong.
In fact, you just seem to be missing the </banner> at the end of the banners with IDs 3, 4, and 5.

Categories