Home  >  Article  >  Backend Development  >  Commonly used regular expressions for php hyperlinks

Commonly used regular expressions for php hyperlinks

WBOY
WBOYOriginal
2016-08-08 09:25:011032browse

1. Delete the hyperlink in the content

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

ereg_replace("]*>|","",$content);

2、 Eliminate hyperlinks containing specific words

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

3. Get the hyperlink text content

//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);

The above introduces the regular expressions commonly used in PHP hyperlinks, including related content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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