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

PHP Home Page

Manual Table of Contents
Up to 文字列
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
文字列
* 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: htmlspecialchars
View the source code for this pageSearch the site



Previous page
 htmlentities
 Updated
Mon, 14 Aug 2000
implode 
Next page


htmlspecialchars

(PHP3 , PHP4 )

htmlspecialchars --  特殊文字を HTML エントリに変換する

説明

string htmlspecialchars (string string)

文字の中には HTML において特殊な意味を持つものがあり、それら 本来の値を表示したければ HTML の表現形式に変換してやらなければ なりません。この関数は、これらの変換を行った結果の文字列を 返します。

メッセージボードやゲストブックのようにユーザーが書きこんだテキス トにおいてHTML のマークアップ用文字を区別する必要がある場合に有用 です。

現在のところ、変換対象となる文字は以下の通りです。

  • '&' (アンパサンド) は '&' になります。

  • '"' (ダブルクォート)は '"' になります。

  • '<' (小なり) は '&lt;' になります。

  • '>' (大なり) は '&gt;' になります。

この関数は上記のあげたもの以外に関しては一切の変換を行わないことに 注意して下さい。すべての変換を行うには htmlentities()を参照してください。

htmlentities() および nl2br()を参照下さい。


User Contributed Notes: htmlspecialchars


aulbach@unter.franken.de
27-Jan-1999 08:48
*This is the corrected version (the manual notes is a fine thing, but the corrections are difficult :-( )*


This function is also very important for forms containing HTML-code. A web-based HTML-editor can look like this:

<PRE>
<FORM ACTION=/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2Fja%2Fbla%26gt&y=1999
<H2>Restaurant Description<H2>
Name of restaurant:
<INPUT TYPE=text NAME="restname"
VALUE="<?
echo HTMLSpecialChars($restname); ?>">
<!-- here it is important to escape the quote char (").
Every browser will get cracy, if you want to edit a string like
$restname="\"The White Horse\""; -->


Input description (you can use HTML - if you can):

<TEXTAREA NAME="descript"><?
echo HTMLSpecialChars($descript);
?></TEXTAREA>
<INPUT TYPE=submit>
</FORM>
</PRE>

Note, that the TEXTAREA includes <B>NO extra space, no newline or anything else</B>. If you do not so, you have programmed a HTML memory leak. :-) The $descript-string is growing between every submit and sends it back to the browser
and the browser will add new chars, cause your
TEXTAREA has told this to him.



thorax@inforocket.com
08-Dec-1999 05:26
<pre>
to convert a document back from this,
do string replacements in this order:

> >
< <
" "
& &

Doing the last phase first will
reveal erroneous results.. For example:

'<' => specialchars() => '&lt;' '&lt;' => convert ampersands => '<' => convert everything else => '<'

</pre>



 About Notes


Previous page
 htmlentities
 Updated
Mon, 14 Aug 2000
implode 
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.