note 55159 added to function.preg-match

From: Date: Tue, 26 Jul 2005 18:46:19 +0000
Subject: note 55159 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-92505@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.preg-match.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55159 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55159&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55159&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55159&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55159&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55159&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55159&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55159&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92505) next »