Forum Moderators: coopster

Message Too Old, No Replies

Making an array of URLS absolute

         

planbeta

8:58 pm on Jun 26, 2003 (gmt 0)

10+ Year Member



I have a list of Urls contained in an array in no particular format (all from 1 site) eg.

[mysite.com...]
/hello.php
mysite.com/test.php
etc.

How can I make all these urls absolute urls and put them back in an array?

If any one has any ideas they would be greatly appreciated.

Cheers

Chris

dingman

9:08 pm on Jun 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[webmasterworld.com...]

Jatar_k, shouldn't that one be in the library?

jatar_k

9:21 pm on Jun 26, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



libraries are still a little confused after the forum split.

daisho

10:07 pm on Jun 26, 2003 (gmt 0)

10+ Year Member



foreach( $urls as $key=>$val ) {
$urls[$key]='http://mydomain.com/'.$val;
}

If I understand right that should do it.

daisho

planbeta

10:51 am on Jun 27, 2003 (gmt 0)

10+ Year Member



Thanks daisho

It's not quite working, it only appears to return the 1st letter of the 1st element in the array.

Am I doing something wrong, I know it collects the links fine, if I remove the 'while'part all the urls are echo'd:

$pattern = "/<a\s+.*?href=[\"\']?([^\"\' >]*)/i";
preg_match_all($pattern,$page,$matches);

while (list ($key, $value) = each ($matches)){
$matches[$key]="http://mydomain.com/".$value;
}

$num = count($matches[0]);

for ($x=0;$x<$num;$x++){
$results = $matches[1][$x];
echo $results.' <br>';
}

To me this make sense logically but doesn't work.

Any ideas?

Thanks again.

Chris

daisho

12:14 pm on Jun 27, 2003 (gmt 0)

10+ Year Member



The problem is that you have a 2D array and not a 1D array.

Try:

foreach( $urls[1] as $key=>$val ) {
$urls[1][$key]='http://mydomain.com/'.$val;
}

daisho

planbeta

12:20 pm on Jun 27, 2003 (gmt 0)

10+ Year Member



Many thanks daisho works perfectly now, looks like I have some reading up on multi-deminsional arrays.

Cheers mate

Chris

daisho

12:31 pm on Jun 27, 2003 (gmt 0)

10+ Year Member



My pleasure. Have fun.

Daisho.