PHP uses regular expression to clear hyperlink text_PHP tutorial

WBOY
Release: 2016-07-13 10:25:23
Original
1130 people have browsed it

You can use $str = preg_replace("/]*href=[^>]*>|]*>/ i","",$strhtml); This paragraph is used to implement the requirements. If you want more solutions, you can refer to the following.
1. Delete the hyperlink in the content

Copy the code The code is as follows:

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

2. Eliminate hyperlinks containing specific words

Copy code The code is as follows:

$find="this string is my find";
$string='replaced';//replace the hyperlink with content
echo ereg_replace(']*)>([^<]*'.$find.'[^>]*)','\2',$content);

3. Get the hyperlink text content

Copy the code The code is as follows:

// Method 1
preg_match_all('/<(a|a)[s]{0,1}[w=":()]*>[nrn]*(check user)[nrn]*/i',$string,$matches);

//Method 2
preg_match_all('/check user/i',$string,$matches);
print_r($matches);

//Method 3
preg_match_all('/]*>[^<]*/i',$string,$matches);
print_r($matches);

//Method 4
preg_match_all('/check user/is',$str,$arr);
print_r($arr);

//Method 5
preg_match_all('/check user/is',$str,$arr);
print_r($arr);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825106.htmlTechArticleYou can use $str = preg_replace("/a[^]*href=[^]*|/[^ a]*a[^]*/i","",$strhtml); This paragraph is used to implement the requirements. If you want more solutions, you can refer to the following. 1. Delete super...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!