#40155 [Fbk->Opn]: Error in sample code in documentation for html_entity_decode

From: Date: Wed, 24 Jan 2007 00:06:48 +0000
Subject: #40155 [Fbk->Opn]: Error in sample code in documentation for html_entity_decode
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969375006@lists.php.net to get a copy of this message
ID: 40155 User updated by: onerob at gmail dot com Reported By: onerob at gmail dot com -Status: Feedback +Status: Open Bug Type: Documentation problem Operating System: any PHP Version: Irrelevant New Comment: Correction and clarification: The PHP4 function example gets confused if you use a decimal HTML entity with a leading zero, e.g. &#039; instead of &#39; 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('&#039;'); ?> 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. Previous Comments: ------------------------------------------------------------------------ [2007-01-20 22:37:22] nlopess@php.net can you please provide an example that exibits the bug in the function? ------------------------------------------------------------------------ [2007-01-17 15:35:32] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40155&edit=1

« previous php.doc (#969375006) next »