Taking apart an IP, converting it and setting it back together


#1

Hey!

I need help solving a little problem of mine.
For a test project we are supposed to create a program or something that converts a IP address into binary and hexadecimal.

The conversion itself is easy enough to do but I struggle with finding an effectice way to take the IP apart before converting it and setting it back together afterwards.

The best way would be to seperate it at the dots but I have no idea how I could go about it.


#2

explode()


#3

http://tutorialspots.com/php-how-to-convert-ip-address-to-binary-string-or-hex-string-3561.html

For Hex, there is also
`$ip_hexed = bin2hex(inet_pton($ip)); *// output: 7f000001 (hexadecimal)

// using SQL
SELECT * FROM user_ip WHERE HEX(ip) = ‘$ip_hexed’`