note 41814 added to function.xml-parse

From: Date: Thu, 22 Apr 2004 20:52:30 +0000
Subject: note 41814 added to function.xml-parse
Groups: php.notes 
Request: Send a blank email to php-notes+get-68551@lists.php.net to get a copy of this message
The XML specifications (1.0, third edition) allow the use of several special characters in XML tags; namely, the period (.), dash (-), and colon (:) which cannot be used within a PHP object or variable name. As such, the XmlC class breaks during the eval() statement when the XML document contains tags using one or more of these characters. You can prevent this by modifying the _startElement() function (adding the preg_replace() statement) to read as follows: <?php function _startElement( $parser, $tag, $attributeList ) { foreach( $attributeList as $name => $value ) { $value = $this->_cleanString( $value ); $object->$name = $value; } $tag = preg_replace("/[:\-\. ]/", "_", $tag); eval( "\$this->pointer[\$this->index]->" . $tag . "[] = \$object;" ); eval( "\$size = sizeof( \$this->pointer[\$this->index]->" . $tag . " );" ); eval( "\$this->pointer[] = &\$this->pointer[\$this->index]->" . $tag . "[\$size-1];" ); ?> This simply replaces the special characters with the underscore (_) character which IS allowed in object/variable names. If you'd prefer a different character or no character to be used, modify the preg_replace() statement appropriately. Hope the info helps. ---- Manual Page -- http://www.php.net/manual/en/function.xml-parse.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41814 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41814&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41814&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68551) next »