Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have the following code that takes the "money" all my XML field but only 1 record and shows me this error:
Error:
Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found in /var/www/client/lib/class/index.php on line 34
Warning: SimpleXMLElement::__construct(): %PDF-1.4 in /var/www/client/lib/class/index.php on line 34
Warning: SimpleXMLElement::__construct(): ^ in /var/www/client/lib/class/index.php on line 34
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /var/www/client/lib/class/index.php:34 Stack trace: #0 /var/www/client/lib/class/index.php(34): SimpleXMLElement->__construct('%PDF-1.4?%?????...') #1 /var/www/client/lib/class/index.php(47): uuid->select() #2 {main} thrown in /var/www/client/lib/class/index.php on line 34
My code:
$data = $this -> conect -> conexion();
$dbquery = $data -> prepare("SELECT *
FROM FILE
ORDER BY ID
");
$dbquery->execute();
while($rows = $dbquery->fetch(PDO::FETCH_ASSOC)){
$string = $rows['BYTES'];
$tuxml = new SimpleXMLElement($string);
echo $tuxml->attributes()->Moneda;
Analysis
Reading the exception information properly reveals the origin of the problem:
Entity: line 1: parser error : Start tag expected, '<' not found
Conclusion: You try to parse something that is no valid XML
SimpleXMLElement->__construct('%PDF-1.4?%?????...')
Conclusion: Looks like you are trying to parse a PDF file as indicated by the magic number "%PDF":
Magic number(s):
All PDF files start with the characters '%PDF-' using the PDF
version number, e.g., '%PDF-1.4'. These characters are in US-
ASCII encoding.
(Source: RFC 3778, Page 9, https://www.rfc-editor.org/rfc/rfc3778)
Resolutions
Ensure your source contains only valid XML files
Try to detect the mime type of the file and skip non XML files
Add a surrounding try-catch block to handle files not parseable as XML
Related
i've a problem with the MongoDB PHP library. I'am trying to find something in a collection but get this error.
Fatal error:
Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Integer overflow detected on your platform: 1484960424767 in C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php:222
Stack trace:
#0 C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php(222): MongoDB\Driver\Cursor->setTypeMap(Array)
#1 C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\FindOne.php(105): MongoDB\Operation\Find->execute(Object(MongoDB\Driver\Server))
#2 C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Collection.php(559): MongoDB\Operation\FindOne->execute(Object(MongoDB\Driver\Server))
#3 C:\xampp\htdocs\gameid\index.php(7): MongoDB\Collection->findOne(Array)
#4 {main} Next MongoDB\Driver\Exception\InvalidArgumentException: Integer overflow detected on your platform: 1484960529934 in C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php:222
Stack trace:
#0 C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php(222): MongoDB\Driver\Cursor->setTypeMap(Array)
#1 C:\ in C:\xampp\htdocs\gameid\vendor\mongodb\mongodb\src\Operation\Find.php on line 222
Here is my source code:
$con = new MongoDB\Client('mongodb://user:pwd#ip:port/ripes');
$con = $con->ripes->games;
$result = $con->findOne(['gameID' => 'KUDl-xvjWkPJkjTRf-']);
What is wrong? If no entry exists with the id, PHP does not report any errors.
I just encountered the same Integer overflow PHP exception. Take a look at your error message again, it is telling you exactly what caused the exception:
Integer overflow detected on your platform: 1484960424767
I was able to use Robo3T (RoboMongo) to view the document in question and see the field with the value that caused the exception (1484960424767 in your case). In the MongoDB document, the field was defined as type NumberLong(), and the value exceeds PHP's capability to parse long integers on the version you're using... most likely 32-bit PHP. Try using 64-bit PHP, if possible.
In my case, the document field was supposed to be a string, so I had to modify the document-creation script to force the value to be a string type.
$doc = array(
"field" => (string)$long_number_value
);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Catchable fatal error: Argument 3 passed to Account::updateUser() must
be an instance of , string given, called in
/Applications/XAMPP/xamppfiles/htdocs/myPage/beta/Includes/includes.php
on line 27 and defined in
/Applications/XAMPP/xamppfiles/htdocs/myPage/beta/classes/Account.php
on line 214
Line 27:
$Account->updateUser($_SESSION["username"], $_POST["password_check"], $_POST["pw1"], $_POST["pw2"]);
Line 214:
public function updateUser($session, $password_check, $pw, $pw2){
How may I fix this? I've tried to rewrite the code multiple times, and tried to change everything on line 214 and below. Also tried to change some of line 27, cannot find the problem and have googled for a long time.
I think there is an invisible character (something like an unbreakable space, or some other invisible utf8 char) in your function declaration and php think it's type hint. You could delete the line and rewrite it. I thnik the probleme is here because must be an instance of , means php want a variable of type "".
Delete and rewrite the function declaration (no copy/paste)
This question already has an answer here:
SimpleXMLElement error but xml is valid [closed]
(1 answer)
Closed 7 years ago.
I have this error when I am reading XML:
Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found
Warning: SimpleXMLElement::__construct(): feed.xml
Warning: SimpleXMLElement::__construct(): ^
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in #1 {main} thrown
PHP:
$feed = new SimpleXMLElement("feed.xml");
echo $feed->SHOPITEM[0]->ID_PRODUCT;
XML:
<?xml version="1.0" encoding="utf-8"?>
<PRODUCTS>
<SHOPITEM>
<ID_PRODUCT><![CDATA[121110]]></ID_PRODUCT>
</SHOPITEM>
<SHOPITEM>
<ID_PRODUCT><![CDATA[121111]]></ID_PRODUCT>
</SHOPITEM>
</PRODUCTS>
Error is on the line where is new SimpleXMLElement("feed.xml) released. Where can be the problem? The XML file is valid.
load the file like this
<?php
$feed = new SimpleXMLElement("xml.xml",null,true);
echo $feed->SHOPITEM[0]->ID_PRODUCT;
//prints 121110
see docs here http://php.net/manual/en/simplexmlelement.construct.php
Use TRUE to specify that data is a path or URL to an XML document instead of string data.
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.
I use PHP's simplexml_load_file() function to call an API that returns changed results based on a Timestamp that I send.
So the API will return only results that have changed since my Timestamp. The problem I am having is if the timestamp is too soon and there are no results for the API to return, then it does not return a proper XML file, instead it will just return a blank page.
This is causing all sorts of problems with simplexml_load_file
Here is a simple test I can run...
$xml = 'http://api.rescuegroups.org/rest/?key=CZivWWGD&type=orgs&limit=300&updatedAfter=1361941202&startPage=1';
$xmlObj = new SimpleXMLElement($xml, NULL, TRUE);
This results in...
Warning: SimpleXMLElement::__construct(): http://api.rescuegroups.org/rest/?key=CZivWWGD&type=orgs&limit=300&updatedAfter=1361941202&startPage=1:1: parser error : Document is empty in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): ^ in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): http://api.rescuegroups.org/rest/?key=CZivWWGD&type=orgs&limit=300&updatedAfter=1361941202&startPage=1:1: parser error : Start tag expected, '<' not found in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): ^ in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php:9 Stack trace: #0 E:\Server\htdocs\labs\freelance\dogAPI\testorg.php(9): SimpleXMLElement->__construct('http://api.resc...', 0, true) #1 {main} thrown in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Now if I pass the API a Timestamp that is further back where there are results, then it will return a perfect XML document.
I am looking for a way to possibly prevent this nasty error from happening somehow?
simplexml_load_file:
Use libxml_use_internal_errors() to suppress all XML errors, and libxml_get_errors() to iterate over them afterwards.
Returns an object of class SimpleXMLElement with properties containing the data held within the XML document, or FALSE on failure.
So suppress the errors and check for FALSE to detect when the query didn't go as expected.
$xml = #simplexml_load_file('http://api.rescuegroups.org/rest/?key=CZivWWGD&type=orgs&limit=300&updatedAfter=1361941202&startPage=1');
if(false !== $xml)
{
// Do anything with xml
}
If there an errors # hide it and return false