Can php delete the content of html tags?

藏色散人
Release: 2023-03-12 21:28:02
Original
1014 people have browsed it

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.

Can php delete the content of html tags?

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='

这里是p标签

这里是img标签这里是a标签
';
Copy after login

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;

Many website articles will contain website names and links, such as Bai Junyao Blog< /a>;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!

source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!