note 54770 added to function.htmlentities

From: Date: Thu, 14 Jul 2005 17:03:19 +0000
Subject: note 54770 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-91975@lists.php.net to get a copy of this message
If you are programming XML documents and are using the htmlentities function, then performing a str_replace on ' into &apos; to set mandatory escape characters you can use this simple function instead. This function, xmlentities, is basically the XML parsing equivalent of htmlentities, with fewer options than its HTML counterpart: <?php // XML Entity Mandatory Escape Characters function xmlentities ( $string ) { return str_replace ( array ( '&', '"', "'", '<', '>' ), array ( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;' ), $string ); } ?> Example: <?php function xmlentities($string) { return str_replace ( array ( '&', '"', "'", '<', '>' ), array ( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;' ), $string ); } echo xmlentities("If you don't use these mandatory escape characters <tags> between </tags>, XML will \"eXtensively\" & \"implicitly\" give you errors."); ?> Produces... If you don&apos;t use these mandatory escape characters &lt;tags&gt; between &lt;/tags&gt;, XML will &quot;eXtensively&quot; &amp; &quot;implicitly&quot; give you errors. ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54770 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54770&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54770&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54770&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54770&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54770&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54770&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54770&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91975) next »