help striping a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

help striping a string

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post 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>");
Post Reply