


PHP removes redundant HTML, Javascript, and Css tags_PHP tutorial
本文章来给大家介绍关于各种PHP去除多余的HTML,Javascrit,Css标签 方法与实现程序,大家可进入参考。
1.不保留任何HTML标签,代码会是这样:echo strip_tags($str);
2. 只保留
一个标签的话,只需要将
字符串写到strip_tags的第二个参数中,代码会是这样:echo strip_tags($str, "
");
3. 我们要保留
与…多个标签,只需要将多个标签用空格分隔后写到strip_tags的第二个参数中,代码会是这样:echo strip_tags($str, "
");
4.保留所有标签,仅仅转义用addslashes(), stripslashes(), htmlspecialchars(), htmlentities(), nl2br() 等函数.
addslashes(), stripslashes() 一般是入数据库和出库的时候使用,以免变量中存储类似引号这些关键词,这样的话,本来是内容的部分却被数据库识别为标识符来执行,就会引起错误.
htmlspecialchars() 函数只用来转义少量HTML, &,双引号,大于号和小于号.并不会全部转换成 HTML 所定的 ASCII 转换
htmlentities() 本函数有点像 htmlspecialchars() 函数,但本函数会将所有 string 的字符都转成 HTML 的特殊字集字符串。不过在转换后阅读网页源代码的方面,会有很多困扰,尤其是网页源代码的中文字会变得不知所云,浏览器上看到的还是正常的。
自带函数去除html标记
strip_tags
去掉 HTML 及 PHP 的标记。
语法: string strip_tags(string str);
传回值: 字串
函式种类: 资料处理
代码如下 | 复制代码 |
?> |
函式将特殊字元转成 HTML 的字串格式 ( &....; )。最常用到的场合可能就是处理客户留言的留言版了。
& (和) 转成 &
" (双引号) 转成 "
< (小于) 转成 <
> (大于) 转成 >
此函式只转换上面的特殊字元,并不会全部转换成 HTML 所定的 ASCII 转换。
这里只替换 html,js,css
代码如下 | 复制代码 |
function get_enhtml($string){ ]*-->/i",'', $content);//注释内容 |
{
$content = preg_replace("/]*>/i",'', $content);
$content = preg_replace("//i", '', $content);
$content = preg_replace("/
$content = preg_replace("/
$content = preg_replace("/]*>/i",'', $content);
$content = preg_replace("//i",'', $content);
$content = preg_replace("/
]*>/i",'', $content);
$content = preg_replace("/
$content = preg_replace("/]*>/i",'', $content);
$content = preg_replace("//i",'', $content);
$content = preg_replace("/]*>/i",'', $content);
$content = preg_replace("/?xml>/i",'', $content);
$content = preg_replace("/
$content = preg_replace("/
$content = preg_replace("/]*>/i",'', $content);
$content = preg_replace("//i",'', $content);
$content = preg_replace("/]*>/i",'', $content);
$content = preg_replace("//i",'', $content);
$content = preg_replace("/]*>/i",'', $content);
$content = preg_replace("//i",'', $content);
$content = preg_replace("//i",'', $content);//注释内容
$content = preg_replace("/
]*-->/i",'', $content);//注释内容
$content = preg_replace("/style=.+?['|"]/i",'',$content);//去除样式
$content = preg_replace("/class=.+?['|"]/i",'',$content);//去除样式
$content = preg_replace("/id=.+?['|"]/i",'',$content);//去除样式
$content = preg_replace("/lang=.+?['|"]/i",'',$content);//去除样式
$content = preg_replace("/width=.+?['|"]/i",'',$content);//去除样式
$content = preg_replace("/height=.+?['|"]/i",'',$content);//去除样式
$content = preg_replace("/border=.+?['|"]/i",'',$content);//去除样式
$content = preg_replace("/face=.+?['|"]/i",'',$content);//去除样式
$content = preg_replace("/face=.+?['|"]/",'',$content);
$content = preg_replace("/face=.+?['|"]/",'',$content);
$content=str_replace( " ","",$content);
return $content;
}
http://www.bkjia.com/PHPjc/628786.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

The top ten safe and reliable exchanges in the 2025 cryptocurrency circle include: 1. Binance, 2. OKX, 3. Gate.io (Sesame Open), 4. Coinbase, 5. Kraken, 6. Huobi Global, 7. Gemini, 8. Crypto.com, 9. Bitfinex, 10. KuCoin. These exchanges are rated as safe and reliable based on compliance, technical strength and user feedback.

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.
