php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40155 Error in sample code in documentation for html_entity_decode
Submitted: 2007-01-17 15:35 UTC Modified: 2007-01-24 11:08 UTC
From: onerob at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: any
Private report: No CVE-ID: None
 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-20 22:37 UTC] nlopess@php.net
can you please provide an example that exibits the bug in the function?
 [2007-01-24 00:06 UTC] onerob at gmail dot com
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.
 [2007-01-24 11:08 UTC] nlopess@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of nlopess
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=5c5a83727ab20878752418ca74f5686d46d5b27d
Log: fix #40155: fix example
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 22:01:33 2025 UTC