PDA

View Full Version : preg Problem



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

chrispian
03-18-2004, 09:51 AM
Isn't . a special character? Don't you have to escape it when matching it?

Mike
03-18-2004, 10:01 AM
Not sure, but I tried doing it and it still came up with the same result...

Mike
03-19-2004, 09:18 AM
Anyone else?