$str = "";
| The code is as follows |
Copy Code |
| $reg = "<a[ss]*?" (href) s*=s* (?) (? =["']) ((["]) (? |
The following example is to get the domain name regular expression in the content
| The code is as follows |
Copy Code |
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, etc. 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.111cn.net";
echo Get_domain ($STR)
The value is 111cn.net