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.

Recommended Answers

All 4 Replies

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

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

If you don't already have a copy of the PHP manual please download a copy and consult it first when you have an issue (as I do).

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 )
Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.