Php regular link-get all links to the content. The following provides two methods for php regular link. they can-get all links to the content and save them to an array. of course, they can also replace all links. The following provides two methods for php regular link. they can get all links to the content and save them to an array. of course, they can also replace all links.
The following provides two regular link methods for php tutorials. they can-get all links to the content and save them to an array. of course, they can also replace all links.
Method 1
Function get_all_url ($ code ){
Preg_match_all ('/"'] +) [" | ']? S * [^>] *> ([^>] +)/I ', $ code, $ arr );
Return array ('name' => $ arr [2], 'URL' => $ arr [1]);
}
Method 2
$ Site = substr ($ url, 0, strpos ($ url, "/", 8); // site
$ Base = substr ($ url, 0, strrpos ($ url, "/") + 1); // Directory of the file
$ Fp = fopen ($ url, "r"); // open the url
While (! Feof ($ fp) $ contents. = fread ($ fp, 1024 );//
$ Pattern = "| href = ['"]? ([^ '"] +) ['"] | U ";
Preg_match_all ($ pattern, $ contents, $ regarr, preg_set_order); // match all href =
For ($ I = 0; $ I
If (! Eregi (": //", $ regarr [$ I] [1]) // whether it is a relative path, that is, whether there are ://
If (substr ($ regarr [$ I] [1],) = "/") // whether it is the root directory of the site
Echo "link". ($ I + 1). ":". $ site. $ regarr [$ I] [1]."
"; // Root directory
Else
Echo "link". ($ I + 1). ":". $ base. $ regarr [$ I] [1]."
"; // Current Directory
Else
Echo "link". ($ I + 1). ":". $ regarr [$ I] [1]."
"; // Relative path
}
Fclose ($ fp );
Bytes. The following section provides two documents about...