★ wanayoo — archive 1999 http://www.php.net/manual/function.htmlentities.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Strings
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Strings
* AddCSlashes
* AddSlashes
* bin2hex
* Chop
* Chr
* chunk_split
* convert_cyr_string
* count_chars
* crc32
* crypt
* echo
* explode
* flush
* get_html_translation_table
* get_meta_tags
* hebrev
* hebrevc
* htmlentities
* htmlspecialchars
* implode
* join
* levenshtein
* ltrim
* md5
* Metaphone
* nl2br
* ob_start
* ob_get_contents
* ob_end_flush
* ob_end_clean
* ob_implicit_flush
* Ord
* parse_str
* print
* printf
* quoted_printable_decode
* quotemeta
* rtrim
* sscanf
* setlocale
* similar_text
* soundex
* sprintf
* strcasecmp
* strchr
* strcmp
* strcspn
* strip_tags
* stripcslashes
* stripslashes
* stristr
* strlen
* str_pad
* strpos
* strrchr
* str_repeat
* strrev
* strrpos
* strspn
* strstr
* strtok
* strtolower
* strtoupper
* str_replace
* strtr
* substr
* substr_count
* substr_replace
* trim
* ucfirst
* ucwords
Manual: htmlentities
View the source code for this pageSearch the site



Previous page
 hebrevc
 Updated
Sat, 12 Aug 2000
htmlspecialchars 
Next page


htmlentities

(PHP3 , PHP4 )

htmlentities --  Convert all applicable characters to HTML entities

Description

string htmlentities (string string)

This function is identical to Htmlspecialchars() in all ways, except that all characters which have HTML entity equivalents are translated into these entities.

At present, the ISO-8859-1 character set is used.

See also htmlspecialchars() and nl2br().


User Contributed Notes: htmlentities


aulbach@unter.franken.de
27-Jan-1999 09:43
Note, that this function currently only escapes ISO-8859-1 (or ISO-latin-1) charset.


Currently, if you don't know what you are really doing, you should try to avoid to use this function.

You *cannot* rely on that the input an user sends you from his browser is ISO-latin-1.


E.g. a user inputs in his charset
a hebrew letter, which has in his charset the same ascii-value as Ä in ISO-latin-1, then this function will convert
it to Ä. [Reminds us to the old DOS-Days where a DOS-Ä looks like a §$'#& under Unix. :-] There is no easy way to convert
this entity back to the correct entity, even if you know the charset, the user has used, cause you
don't know if the user hasn't really meant an Ä and not his hebrew counterpart.


So it is *not quite correct* to use this function as a superior replacement for
things, where HTMLSpecialChars(); is enough, cause you assume, that every instance uses ISO-latin-1.



rob+php@mars.org
15-Sep-1999 10:56
Neither this function nor HTMLSpecialChars() will escape the SGML comment delimiter (--), which can cause problems if you embed the string into an HTML comment.


waller@syrres.com
20-Dec-1999 02:18
Rather interesting. This function fixes the netscape completion problem with html code from a string.
Basically I tried to do something like this
<textarea >
<? echo($data[somestring]);?>
</texarea>
and the variable $data[somestring] was pulled from a database that had html chars in it... so the results was an unfinished table in netscape v.4.7 which I imagine would be also a problem in ealier brow.versions.


suggestion... use this function sparingly because of the sensitive issues with diff.browsers




25-Feb-2000 05:30
To remove html and php tags from a string use strip_tags()


scott.blomquist@iname.com
25-Feb-2000 02:00
The one thing that this function seems to be missing is changing spaces to &nbsp - this is easily corrected as follows:

$trans = get_html_translation_table(HTML_ENTITIES);
$trans[" "] = "&nbsp";
$html = strtr($original, $trans);



mmcc@mmcc.com
01-May-2000 04:43
Scott's solution would be applicable to other situations as well, by simply replacing the `$trans[" "] = " ";` statement with `$trans["'"] = "’";`. The same technique can be used to do ANY sort of similar translation.


brystar@uswest.net
14-May-2000 06:17
By the way.. get_html_translation_table
is only good for php 4.0. Hmmm.. could have saved myself 15 minutes if I had known that.. *grin*



jgilbert@fluidideas.com
21-May-2000 04:18
In reply to a previous statement, wouldn't the following code replace all spaces with   :$trans = get_html_translation_table(HTML_ENTITIES); $trans[" "] = " "; $html = strtr($original, $trans);



To adjust for this problem wouldnt the correct solution be to take two spaces and convert them to a normal space and an   tag. Just a thought. I could be wrong but I could be right. It makes a big difference :)



 About Notes


Previous page
 hebrevc
 Updated
Sat, 12 Aug 2000
htmlspecialchars 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.