Home>Article>Backend Development> Can php delete the content of html tags?

Can php delete the content of html tags?

藏色散人
藏色散人 Original
2021-09-24 09:31:38 1119browse

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标签
';

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;

'); ?> //输出:

这里是p标签

这里是a标签

Many website articles will contain website names and links, such as 6e38f7b81050e0aed24e6556418f8e2cBai Junyao Blog16ef26f8b7ea0fc89bdf90e275a93e5d;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!

Statement:
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