1. Specify tags for regular expression filtering
The code is as follows: |
Copy code |
/** * @ Param $ content * @ Return mixed * Filter the reserved content of Tag. */ Public function delete_tags_a ($ content ){ $ Content = preg_replace ("# <a [^>] *> (.*?) </A> # is "," $1 ", $ content ); Return $ content; } |
2. Filter all html tag content
The code is as follows: |
Copy code |
/** * @ Param $ content * @ Param string $ tag: input the tag to be deleted. * @ Param bool $ ident true: the tag content is retained; false: the tag content is not retained. * @ Return mixed */ Public function delete_tags ($ content, $ tag = 'a', $ ident = true ){ If ($ ident ){ $ Content = preg_replace ("# <{$ tag} [^>] *> (.*?) </{$ Tag }>#is "," $1 ", $ content ); } Else { $ Content = preg_replace ("/(<$ tag. *?> [\ S \ S] *? <\/$ Tag>)/",'', $ content ); } Return $ content; } |
3.
The code is as follows: |
Copy code |
/** * @ Param $ str * @ Return mixed | string * Filter all html tags */ Public function deletehtml ($ str) { $ Str = trim ($ str ); $ Str = strip_tags ($ str ,""); $ Str = preg_replace ("{\ t}", "", $ str ); $ Str = preg_replace ("{\ r \ n}", "", $ str ); $ Str = preg_replace ("{\ r}", "", $ str ); $ Str = preg_replace ("{\ n}", "", $ str ); $ Str = preg_replace ("{}", "", $ str ); $ Str = preg_replace ("{}", "", $ str ); Return $ str; } |
Of course, there are some php functions that can be directly filtered. They will filter all html tags except strings. I will not introduce this function.