In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
The knowledge of this article "php regular expression how to remove the html tag" is not understood by most people, so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "php regular expression how to remove the html tag" article.
The method of removing html tags from php regular expressions: first create a PHP sample file; then remove it through the regular expression "preg_replace ('/\ s (?! src) [a-zA-Z] + = [\"] {1} [^\ "] + [\"\ "] {1} / iu',).
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
How do php regular expressions remove the html tag?
Filtering html tags can have built-in functions in php, but it filters too cleanly, so let's sort out some examples of using regularities to filter specified html tags, as shown below.
When collecting, it is sometimes necessary to filter out redundant tag attributes, such as img tag to filter out all attributes except src attributes, such as deleting titile alt attributes and some foot onclick attributes and so on.
For example
Filter all attributes except src:
The code is as follows:
$str= preg_replace ('/\ s (?! src) [a-zA-Z] + = [\'\ "] {1} [^\'\"] + [\'\ "] {1} / iu',' $str)
The above example code filters out all tag attributes except the src attribute.
Filter Settings filter all properties except alt and src
The code is as follows:
$str = preg_replace ('/\ s (?! (src | alt)) [a-zA-Z] + = [^\ s] * / iu','', $str)
Regular expression that filters the attributes of all html tags:
The code is as follows:
$str = preg_replace ("/] * > / I", "", $str)
Filter only regular expressions for alt attributes:
The code is as follows:
(\ s) alt= [^\ s] *
Regular expression that filters the attributes of all html tags:
The code is as follows:
$search = array ("'] *? >. *?'si", / / remove the javascript "''si", / / remove the HTML tag "'([\ r\ n]) [\ s] +'", / / remove the white space character "& (quot | # 34);'I", / / replace the HTML entity "'& (amp | # 38);'I", "& & (lt | # 60);'I", "'& (gt | # 62)" Run $replace = array ("", "", "\\ 1", "\", "&", "); $html = preg_replace ($search, $replace, $html) as PHP code The above is about the content of this article on "how to remove the html tag from php regular expressions". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.