...

View Full Version : Extracting an element from an array ?



jeddi
11-04-2009, 12:12 PM
Hi,
I am using this expression to pick up the url from my document:


preg_match("/href=\"(.*?)\"/",$text,$matches, PREG_OFFSET_CAPTURE);

When I print the array with:
print_r($matches);

I get this:


Array ( [0] => Array ( [0] => href="http://sbinfocanada.about.com/od/salesselling/a/increasesales.htm" [1] => 55 ) [1] => Array ( [0] => http://sbinfocanada.about.com/od/salesselling/a/increasesales.htm [1] => 61 ) )

How do I pick up this bit "http://sbinfocanada.about.com/od/salesselling/a/increasesales.htm " ?

i.e. $saved_url = $matches[ ??

I tried various combinations like:

echo "<br><br><br>Match: $matches['1[0]']";

but without success :confused:

djm0219
11-04-2009, 12:40 PM
$saved_url = $matches[1][0];

jeddi
11-04-2009, 01:15 PM
Thanks - thats great :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum