note 55158 added to function.htmlentities

From: Date: Tue, 26 Jul 2005 18:45:18 +0000
Subject: note 55158 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-92504@lists.php.net to get a copy of this message
To replace any characters in a string that could be 'dangerous' to put in an HTML/XML file with their numeric entities (e.g. &#233 for é [e acute]), you can use the following function: function htmlnumericentities($str){ return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); };//EoFn htmlnumericentities To change any normal entities (e.g. €) to numerical entities call: $str = htmlnumericalentities(html_entity_decode($str)); ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55158 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55158&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55158&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55158&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55158&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55158&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55158&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55158&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92504) next »