0

Hi,

i have this string:

$link = "http://www.first-link.comhttp://www.second-link.comhttp://www.third-link.com"

i want to exract it to an array like this:

array[0] = http://www.first-link.com
array[1] = http://www.second-link.com
array[2] = http://www.third-link.com

i wrote:

print_r (explode("href",$link));

but now all the string is in array[0] only.
i keep getting

Array ( [0] => http://www.first-link.com ) Array ( [0] => http://www.second-link.com ) Array ( [0] => http://www.third-link.com )

please help.

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by diafol
0

There is no href in your string, so nothing is exploded. Try:

print_r(explode('http://', $link));

oh ! sorry

but Still it shows in array[0]

Array ( [0] => [1] => www.first-link.com ) Array ( [0] => [1] => www.second-link.com ) Array ( [0] => [1] => www.third-link.com )
0

It will because 'http://' is a delimiter not the prompt - "start here". So it will expect a 'value' before the 'http://', even if it is blank / zero-length.

You can address this with array_shift() - it simply pops off the first entry in the array.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.