PHP removes the regular expression of the string hyperlink text

Source: Internet
Author: User
Due to some bad actions performed a long time ago, some junk data exists on the website content page. this morning, I added a method to remove the text of the string hyperlink. next I will use the regular expression to process it. The function of the following instance is to filter all html tags and replace the h1-h5 before... due to some bad actions performed a long time ago, some junk data exists on the website content page. this morning, I added a method to remove the text of the string hyperlink. next I will use the regular expression to process it.

The functionality of the following instance is to filter all html tags and replace all text before the h1-h5

 %% '"; $ Query = mysql_query ($ SQL) or die (mysql_error (); if (mysql_num_rows ($ query) {while ($ rs = mysql_fetch_array ($ query )) {// print_r ($ rs); $ t = stripslashes ($ rs ['field']); $ str = nl2br (strip_tags (addslashes (removelink ($ t); $ SQL = "update table name set field = '$ str 'Where id = ". $ rs ['id']; if (mysql_query ($ SQL) {echo $ rs ['id']. 'success
';} Else {echo mysql_error () ;}} else {echo' has been updated and has not recorded '. $ SQL .'
';}} Function removelink ($ t) {// $ str = preg_replace ("/] * href = [^>] *> | ] *>/I "," ", $ t); $ str = preg_replace ("/(? Is )(? <= ).*? (? =)/I "," ", $ t); $ str = preg_replace ("/(? Is )(? <= ).*? (? =)/I "," ", $ str); $ str = preg_replace ("/(? Is )(? <= ).*? (? =)/I "," ", $ str); $ str = preg_replace ("/(? Is )(? <= ).*? (? =)/I "," ", $ str); $ str = preg_replace ("/(? Is )(? <= ).*? (? =)/I "," ", $ str); return re_h ($ str);} function re_h ($ str) {$ str = str_replace ('','', $ str); $ str = str_replace ('','', $ str); $ str = str_replace ('','', $ str ); $ str = str_replace ('','', $ str); $ str = str_replace ('','', $ str); $ str = str_replace ('', '', $ str); $ str = str_replace ('', '', $ str); $ str = str_replace ('', '', $ str ); $ str = str_replace ('','', $ str); $ str = str_replace ('','', $ str); re Turn $ str ;}?>

The following regular expression is used.

preg_replace("/(?is)(?<=).*?(?=)/i","",$t);

This is the core code.


For example, if you want to remove the hyperlink content from the text, you need to use a regular expression. For example, you can use $ str = preg_replace ("/] * href = [^>] *> | ] *>/I "," ", $ strhtml); to meet the requirements, see the following for more solutions.

1. delete the hyperlink in the content

ereg_replace(']*)>([^<]*)','2',$content);ereg_replace("]*>|","",$content);

2. remove hyperlinks containing specific words

$ Find = "this string is my find ";

$ String = 'replaced'; // The content of the hyperlink.

Echo ereg_replace ('] *)> ([^ <] *'. $ find. '[^>] *)', '2', $ content );

Site original, reproduced must indicate the source of http://www.phprm.com otherwise the consequences at your own risk


Permanent address:

Reprint at will ~ Please bring the tutorial URL ^

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.