Re: parse HTML page
| From: | Wico de Leeuw | Date: | Tue, 25 Jul 2000 16:10:53 +0000 |
| Subject: | Re: parse HTML page | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8072@lists.php.net to get a copy of this message | ||
Hiya
try this [from heart, not tested]
if ($data = @file("http://server.ext/page.html")) {
if (preg_match_all("'(href|scr)\s*=\s*([\'\"])?((?(2).*?(?=\\2)|[^>\s]+))[\'\"]?'im', $data)) {
// urls found, $data[x][3] will contain the urls
var_dump($data);
} else
// no urls found
}
}
Greetz,
Wico
At 08:45 25-7-00 -0700, O. wrote:
""Erb, Maria"" <merb@keene.edu> wrote in message news:CFD3579B7DE2D111A7C000805F9F61AD0162A961@dinsmore.keene.edu... hi, I need to be able to parse an HTML page and extract the URL's from it. I am really unsure how to go about doing this. Any suggestions? I had to do this recently. fgetss() is useful for this, as are regular expressions (but I can't figure regexps out for the life of me). Try this set of steps ... - Open the file for input, and perhaps another file for output (or use an array for output) - Strip all of the extraneous tags from each line using $string = fgetss($file,4096,"<a></a>") - In the same loop, check each string for "<a"; if one is found, search for the matching "</a>" - Use the appropriate string functions to get this link into a single string (functions like substr, strpos, etc), then put that string in your array. - You can write additional functions with regexp's or plain ol' string routines to get info like the link itself, the description, and other information included in a <A> tag. Note that a single regexp could probably do the work of the 2nd, 3rd, and 4th steps. -- O. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net