html标签相关联的字符串格式化
如果用普通的post接收网页输入信息
<?php
if(isset($_POST['dosubmit'])) {
$title = $_POST['title'];
echo $title."<br>";
//echo stripslashes(addslashes($title))."<br>";
//echo htmlspecialchars($title);
}
?>
<br>
<form action="" method="post">
title: <input type="text" name="title" value="" />
<input type="submit" name="dosubmit" value="提交" /><br>
</form>
这是我输入1234的结果,但是细思恐极啊,我要是为了破坏你的网页,传进去坏坏的代码怎么办?
这时,我们的HTML标签相关联的字符串格式化横空出世
stripslashes(addslashes($title))输入什么显示什么 删除转义字符 加转义字符是add……()
函数:nl2br( )
语法:string nl2br ( string string ) 将字符串中”\n”转成HTML换行符“
”
函数:htmlspecialchars()
语法:string htmlspecialchars ( string string [,
int quote_style [, string charset]] ) 把指定特殊符号转换成实体,如<>
'&' :'&' '“':'"'
''' :''' ' '>' :'>'
函数: htmlentities()
语法:string htmlentities ( string string [, int quote_style [,string charset]]) 可以将所有的非ASCII码转换成对应实体代码。
函数:string strip_tags()
语法:string strip_tags(string str[,string allowable_tags]) 删除HTML的标签函数 后面的参数是指定要保留的标签
立即学习“PHP免费学习笔记(深入)”;
以上就介绍了php字符串处理函数(下),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。











