PHP Tutorials Match URL Regular expression code
This is a PHP regular expression that gets all the links in the article content
$str = "";
$reg = "<a[ss]*?" (href) s*=s* (? =["']) ((["]) (? <href>[^ "']*) 2) | (? <src>[^s>]+)) [ss]*?> "//The following example is to get the domain name regular expression in the content
Function Get_domain ($url) {
$pattern =/[w-]+. ( COM|NET|ORG|GOV|CC|BIZ|INFO|CN) (. ( CN|HK)).
Preg_match ($pattern, $url, $matches);
if (count ($matches) > 0) {
return $matches [0];
}else{
$rs = Parse _url ($url);
$main _url = $rs ["Host"];
if (!strcmp (Long2ip (sprintf ("%u", Ip2long ($main _url)), $main _url)) {
return $ Main_url;
}else{
$arr = Explode (".", $main _url);
$count =count ($ ARR);
$endArr = Array ("com", "net", "org", "3322");//com.cn net.cn
if ( In_array ($arr [$count-2], $ENDARR) {
$domain = $arr [$count-3]. "." $arr [$count-2]. $arr [$count-1];
}else{
$domain = $arr [$count-2]. "." $arr [$count-1];
}
return $domain;
}
}
//instance
$STR = "Jfkdlajfdafdjak; Www.jzread.com ";
echo Get_domain ($str)
//The value is jzread.com