php can delete the content of html tags. The specific method is: 1. Use the function strip_tags that comes with php to delete all or keep the specified html tags; 2. Delete the specified html tags and tag content through the strip_html_tags() function. etc.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
Can php delete the content of the html tag?
How to delete the html tag and the content within the tag
Frequently Those who pick up other people’s website articles; I mean those who collect in batches without reading the content at all, and will inevitably use the function of deleting html tags; here are three methods for different purposes;
$str='<div><p>这里是p标签</p><img src="/static/imghwm/default1.png" data-src="" alt=" class="lazy" alt="这里是img标签"><a href="">这里是a标签</a><br></div>';
1: Delete all or keep the specified html tags
PHP’s own function strip_tags can meet the requirements,
Usage method: strip_tags(string,allow);
String: The string that needs to be processed;
‐ . tag; and I just want to delete a specified one; then I have to write a lot of tags that need to be retained; So there is a second method;
2: Delete the specified html tag
How to use :strip_html_tags($tags,$str);
to be deleted. : Delete the content of the label and label
How to use: Strip_html_TAGS ($ tags, $ Str); : String that needs to be processed;
<?php echo strip_tags($str,'<p><a>'); ?> //输出:<p>这里是p标签</p><a href="">这里是a标签</a>
Many website articles will contain website names and links, such as Bai Junyao Blog;This function is designed to treat this kind of problem; Don’t use this function to collect this site; otherwise I guarantee that I won’t beat you to death;
4: The ultimate function, delete the specified tag; delete or retain the content in the tag ;
How to use: strip_html_tags($tags,$str,$content);
String;
The above is the detailed content of Can php delete the content of html tags?. For more information, please follow other related articles on the PHP Chinese website!

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
