note 92034 modified in ref.simplexml by danbrown

From: Date: Mon, 06 Jul 2009 16:08:21 +0000
Subject: note 92034 modified in ref.simplexml by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157972@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"?> <svg xmlns:dc="http://www.example.com/dc" xmlns:cc="http://www.example.com/cc" xmlns:rdf="http://www.example.com/rdf" xmlns:svg="http://www.example.com/svg" xmlns="http://www.example.com/" xmlns:sodipodi="http://www.example.com/sodipodi" xmlns:inkscape="http://www.example.com/inkscape" 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"; ?> --was-- 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"; ?> http://php.net/manual/en/ref.simplexml.php

« previous php.notes (#157972) next »