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))
函数: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教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号