Hi,
I'm going to need to use arrays quite well soon for my project I'm doing, but I can't quite understand them.
I found this snippet off a website as an example:
$input = file_get_contents("http://www.google.co.uk");
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
?>
<br><br>
<?php
echo $match[2];
#echo $match[3];
}
I've been working with it tweaking and all for ages, and I can't get it to work the way I want it to. I think it's because I don't know what the type of array is, maybe multidimensional, but I don't know what that means.
The problem is when I use it and use: Print_r($match) to find out the indexes so I can actually use some of the elements in the array, I get repeating element indexes 😕
Like this:
Array ( [0] => Images [1] => " [2] => /imghp?hl=en&tab=wi&ie=UTF-8 [3] => Images )
Array ( [0] => Groups [1] => " [2] => http://groups.google.co.uk/grphp?hl=en&tab=wg&ie=UTF-8 [3] => Groups )
Array ( [0] => News [1] => " [2] => http://news.google.co.uk/nwshp?hl=en&tab=wn&ie=UTF-8 [3] => News )
Array ( [0] => Froogle [1] => " [2] => http://froogle.google.co.uk/frghp?hl=en&tab=wf&ie=UTF-8 [3] => Froogle )
Array ( [0] => more » [1] => " [2] => /intl/en/options/ [3] => more » )
Array ( [0] => Advanced Search [1] => [2] => /advanced_search?hl=en [3] => Advanced Search )
Array ( [0] => Preferences [1] => [2] => /preferences?hl=en [3] => Preferences )
Array ( [0] => Language Tools [1] => [2] => /language_tools?hl=en [3] => Language Tools )
Array ( [0] => Advertising Programmes [1] => " [2] => /ads/ [3] => Advertising Programmes )
Array ( [0] => Business Solutions [1] => [2] => /services/ [3] => Business Solutions )
Array ( [0] => About Google [1] => [2] => /intl/en/about.html [3] => About Google )
Array ( [0] => Go to Google.com [1] => [2] => http://www.google.com/ncr [3] => Go to Google.com )
Could someone please explain why they repeat and how I can solve it?
Thanks