Bilal Bilal - 16 days ago 5
PHP Question

SimpleXMLElement Returns null on 600dpi background

I have went through a lot of similar questions.i couldn't find an answer to my problem.

I have an

svg image
.I'm trying to get contents from it by using
SimpleXMLElement
.

$svgimage = path to svg image;
$svgString=file_get_contents($svgimage) ;//returns image

$svg = new SimpleXMLElement( $svgString );//returns nothing


I have been using a
300dpi
image as background of svg image.Now i changed it to
600dpi
.After that
$svg
returns nothing.I have no idea why SimpleXMLElement doesn't work on 600dpi.


Error Log

Warning: SimpleXMLElement::__construct(): Entity: line 29: parser error : AttValue length too long

Warning: SimpleXMLElement::__construct():

xlink:href="data:image/x-ms-bmp;base64,Qk1mDokAAAAAADYAAAAoAAAAZQgAAHEFAAAB

Warning: SimpleXMLElement::__construct(): Entity: line 29: parser
error : attributes construct error

Warning: SimpleXMLElement::__construct(): Entity: line 29: parser
error : Couldn't find end of Start Tag image line 20

Warning: SimpleXMLElement::__construct(): Entity: line 709: parser
error : internal error: Huge input lookup

Warning: SimpleXMLElement::__construct():

name="order-id"


Size of SVG is 12MB


Any kind of help would be appreciated.

Answer

Try this:

simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE)

http://php.net/manual/en/libxml.constants.php XML_PARSE_HUGE flag relaxes any hardcoded limit from the parser. This affects limits like maximum depth of a document or the entity recursion, as well as limits of the size of text nodes.