note 69478 added to function.preg-replace

From: Date: Thu, 07 Sep 2006 09:21:24 +0000
Subject: note 69478 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-116805@lists.php.net to get a copy of this message
Wasted several hours because of this: $str='It's a string with HTML entities'; preg_replace('~&#(\d+);~e', 'code2utf($1)', $str); This code must convert numeric html entities to utf8. And it does with a little exception. It treats wrong codes starting with &#0 The reason is that code2utf will be called with leading zero, exactly what the pattern matches - code2utf(039). And it does matter! PHP treats 039 as octal number. Try print(011); Solution: preg_replace('~&#0*(\d+);~e', 'code2utf($1)', $str); ---- Server IP: 195.248.191.91 Probable Submitter: 193.201.100.84 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/69478 Del: integrated -- https://master.php.net/note/delete/69478/integrated Del: useless -- https://master.php.net/note/delete/69478/useless Del: bad code -- https://master.php.net/note/delete/69478/bad+code Del: spam -- https://master.php.net/note/delete/69478/spam Del: non-english -- https://master.php.net/note/delete/69478/non-english Del: in docs -- https://master.php.net/note/delete/69478/in+docs Del: other reasons-- https://master.php.net/note/delete/69478 Reject -- https://master.php.net/note/reject/69478 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116805) next »