|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-17 15:35 UTC] onerob at gmail dot com
Description: ------------ Single quotes need to be double quotes in the second line of the PHP 4 equivalent function example of html_entity_decode() that is provided by the documentation. http://uk2.php.net/manual/en/function.html-entity-decode.php#61610 Reproduce code: --------------- n/a Expected result: ---------------- n/a Actual result: -------------- n/a PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 23:00:01 2025 UTC |
Correction and clarification: The PHP4 function example gets confused if you use a decimal HTML entity with a leading zero, e.g. ' instead of ' For example, the following code should really output a single quote character but actually outputs nothing - <?php // For users prior to PHP 4.3.0 you may do this: function unhtmlentities($string) { // replace numeric entities $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec ("\\1"))', $string); $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string); // replace literal entities $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl); return strtr($string, $trans_tbl); } echo unhtmlentities('''); ?> To correct this, changing the following line from $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string); to $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string); is adequate (double quotes added around \\1). A similar fix could no doubt be provided for the preceding line in the function, also.