最終更新:2011-11-01 (火) 06:04:52 (4531d)
Smarty/escape
http://www.smarty.net/docsv2/ja/language.modifier.escape.tpl
エスケープの種類
種類 | 説明 | 呼ばれる関数 | 例 |
html | 特殊文字を HTML エンティティに変換する | htmlspecialchars | |
htmlall | 適用可能な文字を全て HTML エンティティに変換する | htmlentities | |
url | rawurlencode? | ||
urlpathinfo | str_replace('%2F','/',rawurlencode($string) | ||
quotes | escape unescaped single quotes | preg_replace("%(?<!\\\\)'%", "\\'", $string); | 'sample' -> ¥'sample¥' |
hex | escape every character into hex | $return .= '%' . bin2hex($string[$x]); | |
hexentity | $return .= '&#x' . bin2hex($string[$x]) . ';'; | ||
decentity | $return .= '&#' . ord($string[$x]) . ';'; | ||
javascript | escape quotes and backslashes, newlines, etc. | strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/')) | |
safe way to display e-mail address on a web page | str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string) | homge@hoge.hoge -> hoge [AT] hoge [DOT] hoge | |
nonstd | escape non-standard chars, such as ms document quotes |