tmlentities htmlspecialchars
htmlentities ---会对中文产生乱码,所以POST时(即提交表单)时不要用htmlentities
而GET(即URL提交时)就最好用htmlentities
<?php
if ( isset( $_POST ) )
$postArray = &$_POST ; // 4.1.0 or later, use $_POST
else
$postArray = &$HTTP_POST_VARS ; // prior to 4.1.0, use HTTP_POST_VARS
foreach ( $postArray as $sForm => $value )
{
if ( get_magic_quotes_gpc() )
{
$postedValue = htmlspecialchars( stripslashes( $value ) ) ;
echo 'lllllll';
}
else
$postedValue = htmlspecialchars( $value ) ;
// $postedValue = stripslashes( $value ) ;
//else
//$postedValue = $value ;
?>
<tr>
<th style='vertical-align: top'><?php echo $sForm?></th> -----这是表单名
<td><pre><?php echo $postedValue?></pre></td>
</tr>
==============
以上是CKEDITOR的样例。
从中看出:如果get_magic_quotes_gpc(),那么就相当于addslashes,那么就要解开来,用stripslashes
------------------------
stripslashes是去掉斜杠而已,没有去掉什么其他的, addslashes是给单引号,双引号,斜杠加上斜杠,
htmlspecialchars()是把单引号,双引号,<.>,# 转换成html实体
htmlspecialchars_decode则是用来输出html,
学会使用,如要给新闻标题加color等时,入库时要消HTML(同时也要消javascript),前台显示时要HTML.
htmlentities也是转换成html实体
$str='<a href='test.html'> abc '<& >' </a>';
echo htmlentities($str);
$str='<a href='test.html'> abc '<& >' </a><script>alert(222);</script>';
echo htmlspecialchars($str);
echo htmlspecialchars_decode(htmlspecialchars($str));
=========
htmlspecialchars htmlentities - stripslashes - addslahes
最新推荐文章于 2024-06-04 09:39:22 发布