Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize html tag completion and filtering of Web content by PHP

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "PHP how to achieve web content html tag completion and filtering", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "PHP how to achieve web content html tag completion and filtering" it!

If the html tags of your page content are not displayed completely, some form tags are incomplete and the page is confused, or some local html pages other than your content are included, we can write a function method to complete the html tags and filter out useless html tags.

Php makes HTML tags automatically complete, close, filter function method 1:

Code:

Function closetags ($html) {preg_match_all ('# iU', $html, $result); $closedtags = $result [1]; $len_opened = count ($openedtags); if (count ($closedtags) = = $len_opened) {return $html;} $openedtags = array_reverse ($openedtags); for ($iTun0; $I < $len_opened; $iTunes +) {if (! in_array ($openedtags [$I], $closedtags)) {$html. ='' } else {unset ($closedtags [array _ search ($openedtags [$I], $closedtags)]);} return $html;}

Closetags () parsing:

Array_reverse (): this function flips the order of the elements in the original array, creates a new array, and returns. If the second parameter is specified as true, the key name of the element remains unchanged, otherwise the key name will be lost.

Array_search (): array_search (value,array,strict), this function looks for a key value in the array like in_array (). If the value is found, the key name of the matching element is returned. If it is not found, false is returned. If the third parameter strict is specified as true, the key name of the corresponding element is returned only if the data type and value are the same.

Php makes HTML tags automatically complete, close, and filter function method 2:

Function checkhtml ($html) {$html = stripslashes ($html); preg_match_all ("/\ $val) {$string [$key] = shtmlspecialchars ($val);}} else {$string = preg_replace ('/ & (# (\ d {3L5} | x [a-fA-F0-9] {4}) | [a-zA-Z] [a-z0-9] {2} 5})) ) /','&\\ 1, str_replace (array ('&','','), array ('&','','), $string));} return $string;}

Checkhtml ($html) parsing:

Stripslashes (): the function removes the backslash added by the addslashes () function. This function is used to clean up data retrieved from a database or HTML form.

Thank you for your reading, the above is the content of "PHP how to achieve web content html tag completion and filtering". After the study of this article, I believe you have a deeper understanding of how PHP realizes web content html tag completion and filtering, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report