note 92034 added to ref.simplexml
| From: | DouglasMarsh at osu1 dot php dot net | Date: | Mon, 06 Jul 2009 15:53:23 +0000 |
| Subject: | note 92034 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-157969@lists.php.net to get a copy of this message | ||
SimpleXML is really nice for loading/converting XML data into native PHP data structures. I was
considering crude searching of SVG for the width/height and since it really is an XML file... I
found a SUPER easy method for parsing out the information I wanted:
<?php
// putting incomplete SVG data inline for readability
$RawXML = <<< XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (URL REMOVED TO MAKE POSTING HAPPY) -->
<svg
xmlns:dc="URL REMOVED TO MAKE POSTING HAPPY"
xmlns:cc="URL REMOVED TO MAKE POSTING HAPPY"
xmlns:rdf="URL REMOVED TO MAKE POSTING HAPPY"
xmlns:svg="URL REMOVED TO MAKE POSTING HAPPY"
xmlns="URL REMOVED TO MAKE POSTING HAPPY"
xmlns:sodipodi="URL REMOVED TO MAKE POSTING HAPPY"
xmlns:inkscape="URL REMOVED TO MAKE POSTING HAPPY"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.46"
width="586.25"
height="743.75"
xml:space="preserve"
sodipodi:docname="some_svg_file.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<!-- portions removed to keep this short -->
</svg>
XML;
$svg = new SimpleXMLElement($RawXML);
$height = $svg['height'];
$width = $svg['width'];
echo "The width x height is: ${width} x ${height} \n";
?>
----
Server IP: 64.71.164.2
Probable Submitter: 134.39.241.100 (proxied: 134.39.240.249)
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- https://master.php.net/note/edit/92034
Del: integrated -- https://master.php.net/note/delete/92034/integrated
Del: useless -- https://master.php.net/note/delete/92034/useless
Del: bad code -- https://master.php.net/note/delete/92034/bad+code
Del: spam -- https://master.php.net/note/delete/92034/spam
Del: non-english -- https://master.php.net/note/delete/92034/non-english
Del: in docs -- https://master.php.net/note/delete/92034/in+docs
Del: other reasons-- https://master.php.net/note/delete/92034
Reject -- https://master.php.net/note/reject/92034
Search -- https://master.php.net/manage/user-notes.php