This is a php Regular Expression for getting all links in the article content. This is a php Regular Expression for getting all links in the article content.
Script ec (2); script
$ Str = "";
The Code is as follows: |
|
$ Reg = "[^" '] *) | (? [^ S>] +) [sS] *?> "; |
// The following example shows how to obtain the regular expression of the domain name in the content.
The Code is as follows: |
|
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.111cn.net ";
Echo get_domain ($ str)
// Obtain the value 111cn.net.