Because N long ago did some very bad action caused the site content page has some garbage data, this morning, the whole of a string to remove the hyperlink text method, I combine the regular to deal with.
The function of the following instance is to filter all HTML tags and replace all text before H1-H5
| The code is as follows |
Copy Code |
for ($i =1; $i <=5; $i + +) { $sql = "SELECT * from ' table name ' WHERE ' field ' like ' % '";
$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 with no record '. $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); return $str; } |
It uses the following regular expression
| The code is as follows |
Copy Code |
Preg_replace ("/(? is) (? <= ).*? (?= )/I "," ", $t); |
This is the core code.
For example, you need to remove the content of hyperlinks in the text, you need to use regular expressions. For example you can use $STR = Preg_replace ("/]*href=[^>]*>| ]*>/i "," ", $strhtml); This section to achieve the requirements, if you want more solutions, you can see the following.
1. Delete the hyperlinks in the content
| The code is as follows |
Copy Code |
Ereg_replace (']*) > ([^<]*) ', ' \2 ', $content); Ereg_replace ("]*>|", "", $content); |
2. Eliminate hyperlinks that contain specific words
| The code is as follows |
Copy Code |
$find = "This string is my find"; $string = ' replaced ';//To replace the hyperlink with the content Echo ereg_replace (']*) > ([^<]* '. $find. ' [^>]*] ', ' \2 ', $content); |
Original site, reprint must indicate the source www.bKjia.c0m otherwise the consequences of self-esteem
http://www.bkjia.com/PHPjc/633130.html www.bkjia.com true http://www.bkjia.com/PHPjc/633130.html techarticle because N long ago did some very bad action caused the site content page has some garbage data, this morning, the whole of a string to remove the hyperlink text method, the following I combine the regular to ...