Mike
03-18-2004, 09:30 AM
Hi all,
I've bumped into a small problem with ereg.
I'm getting all the html links from a site, and making a list. That part works fine. But I want to list all the links that start with http://www. below them (so they could be listed twice). That part doesn't work.
<?php
$file_lines = file('http://www.example.com);
foreach($file_lines as $file) {
if(preg_match_all('#<a\s+?href=["\'](.+?)["\'].*?>#', $file, $matches)) {
for ($i = 0; $i < count($matches[1]); $i++)
echo $matches[1][$i] . '<br />';
}
}
$match = implode("-", $matches);
if(preg_match_all('#(http://www).+#', $match, $total)) {
for ($x = 0; $x < count($total[1]); $x++)
echo $total[1][$x] . '<br />';
}
?>
I get no errors, but the first list with all the links is the only thing that shows up.
Anyone know what's wrong?
Thanks a lot,
Mike
I've bumped into a small problem with ereg.
I'm getting all the html links from a site, and making a list. That part works fine. But I want to list all the links that start with http://www. below them (so they could be listed twice). That part doesn't work.
<?php
$file_lines = file('http://www.example.com);
foreach($file_lines as $file) {
if(preg_match_all('#<a\s+?href=["\'](.+?)["\'].*?>#', $file, $matches)) {
for ($i = 0; $i < count($matches[1]); $i++)
echo $matches[1][$i] . '<br />';
}
}
$match = implode("-", $matches);
if(preg_match_all('#(http://www).+#', $match, $total)) {
for ($x = 0; $x < count($total[1]); $x++)
echo $total[1][$x] . '<br />';
}
?>
I get no errors, but the first list with all the links is the only thing that shows up.
Anyone know what's wrong?
Thanks a lot,
Mike