PHP reads the function of the link to a site
Author: qiushuiwuh Joined: 2003-11-22 Views: 118 works: a site to read the source file, and then use the regular analysis of its source code, get all the links ********** qiushuiwuhen? (2002-5-20) *********** / IF (Empty ($ URL)) $ URL = "http://www.9cbs.net/expert/"; // Set URL $ Site = SUBSTR ($ URL, 0, STRPOS ($ URL, "/", 8)); // Site $ BASE = SUBSTR ($ URL, 0, STRPOS ($ URL, "/") 1); // File where the file is located $ fp = fopen ($ URL, "R"); // Open URLWHILE (! 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 < Count ($ regarr); $ i ) {// Traverse all match if (! EREGI (": ///", $ regarr [$ i] [1])) // Is it a relative path, that is, it is also: / / IF (SubStr ($ RARR [$ I] [1], 0, 1) == "/") // is whether it is the root directory Echo "Link". ($ I 1). ":". $ RARR [$ I] [1]. "" "" Else Echo "LINK". ($ I 1). ":". $ base. $ regarr [$ I] [ 1]. ""; // Current directory Else Echo "LINK". ($ I 1). ":" $ Regarr [$ I] [1]. "; // Relative path} fclose ($ fp);?>