Php regular expressions filter hyperlinks and determine whether the link text is a URL preg_replace_callback function usage $ str & lt; ahrefwww. scutephp. comtarget_blank & gt; www.scutephp.com & lt; a & gt; & lt; ahrefwww.scutephp.com & gt; cxybl php regular filtering hyperlink and determining whether the link text is the URL preg_replace_callback function usage
$ Str = 'www .scutephp.com cxybl filter hyperlink '; $ str = filter_url ($ str );
The function code is as follows:
Function filter_url ($ str) {return preg_replace_callback ("/] +> (. + ?) <\/A>/I "," filter_url_callback ", $ str);} function filter_url_callback ($ matchs) {$ str = $ matchs [1]; if (! $ Str) return ''; $ arr = array ('www. ', 'http ://','. com ','. cn ','. org ','.. net ','. cc '); foreach ($ arr AS $ k => $ v) {if (stripos ($ str, $ v )! = False) return '';} return $ str ;}
If the hyperlink text is www.scutephp.com, it will also be filtered out, but if it is pure text, it will be retained.