Home > Backend Development > PHP Tutorial > PHP string processing function (Part 2)

PHP string processing function (Part 2)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:03:57
Original
955 people have browsed it

HTML标签相关联的字符串格式化

如果用普通的post接收网页输入信息

<?php if(isset($_POST[&#39;dosubmit&#39;])) {
		$title = $_POST[&#39;title&#39;];
		echo $title."<br>";
		//echo stripslashes(addslashes($title))."<br>";
		//echo htmlspecialchars($title);
	}
?>
<br>
Copy after login
title:

PHP string processing function (Part 2)这是我输入1234的结果,但是细思恐极啊,我要是为了破坏你的网页,传进去坏坏的代码怎么办?

这时,我们的HTML标签相关联的字符串格式化横空出世

stripslashes(addslashes($title))
Copy after login
输入什么显示什么 删除转义字符 加转义字符是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 string processing function (Part 2),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template