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. ' 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('&#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] [EMAIL PROTECTED]

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

Reply via email to