Jump to content

SOLVED - What might be wrong with this code?


kektex

Recommended Posts

[b]I found the error in the code...I had some blank spaces in a place there shouldn´t have been any.The regex was correct.Thanks for the help thorpe![/b]

Hello,
Im trying to extract all URLs from an html file.The links I´m interested in have this formatting:
<a style="clear:all;" href="http://www.example.com">Example Anchor</a>

I´m using this code to extract the URL:
[code]
$data = file_get_contents('file.html');
preg_match_all("/<a style=\"clear:all\;\" href=\"(.+?)\"> /", $data, $result);

$result = $result[3];
echo $result."<br />";

[/code]

All I get is the following error:
Notice: Undefined offset: 3 in c:\xxxxx.php on line 9

I´m a newbie to PHP and I´ve been reading about regex and arrays but I can´t seem to find what´s wrong here.I´m thinking it´s the array since the error says something about the offset.I´m just basing this on some code I found that does a similar job to the one I need to do.

Thanks for any help!
Replace this...

[code=php:0]
$result = $result[3];
[/code]

with...

[code=php:0]
print_r($result);
[/code]

The error is indicating that there is no 3rd arraay element. Im sorry, I'm no good with regular exressions or I might be of more assistance, at least this way though we'll be able to see what $result looks like.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.