Page 1 of 1

help striping a string

Posted: Wed Jan 15, 2003 9:18 am
by penguinboy
i'm trying to strip IPs

like...

$ip = "123.456.78.9";

and i want to break it up into

123
456
78
9

so i want to break it up based on the period

i figure i'd have to use strchr, but it only looks for the first instance of "."
any help???

thanks
--pb

Posted: Wed Jan 15, 2003 9:23 am
by twigletmac
You can use explode() to do this:

Code: Select all

$ip = "123.456.78.9";
$ip_array = explode('.', $ip);
will explode out the parts into separate array elements.

Mac

Posted: Wed Jan 15, 2003 9:35 am
by penguinboy
heh

i just figured it out, came back to post the code.
twigletmac beat me too it though...

this is how i did it

$ip = explode(".", "$row[address]");

print("$ip[0]<br>$ip[1]<br>$ip[2]<br>$ip[3]<br>");