Quick Question

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
Zanne
Forum Newbie
Posts: 15
Joined: Mon Feb 04, 2008 3:38 pm

Quick Question

Post by Zanne »

Alright, I've been coding PHP for about 2 years now, but I have this one question that I can't seem to find the answer to.

I'm creating this program that turns an IP into binary, but I'm running into this small issue.

Right now, I have to create 4 seperate text boxes for a user to input the IP address in, but I would just prefer the user to use 1 textbox and put in the whole IP. This leads me to my question.

An IP is 4 sets of numbers with periods in between., ex 11.222.33.44. I want to be able to turn this IP address into 4 variables holding the int, like this:

$ip1="11";
$ip2="222";
$ip3="33";
$ip4="44";

Now, I am NOT looking for a code that will get rid of the "." and just give me "112223344".

Is there a code that is capable of doing this?
Last edited by Zanne on Mon Feb 04, 2008 3:50 pm, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Quick Question

Post by Benjamin »

Code: Select all

$array = explode('.', $ip);
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Quick Question

Post by califdon »

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Quick Question

Post by RobertGonzalez »

Moved to PHP - Code.
Zanne
Forum Newbie
Posts: 15
Joined: Mon Feb 04, 2008 3:38 pm

Re: Quick Question

Post by Zanne »

Thank you all very much. The code works fine =)

God bless,

Zanne
Post Reply