Snipping an IP Address

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
hewbert
Forum Newbie
Posts: 1
Joined: Mon Feb 03, 2003 8:39 am

Snipping an IP Address

Post by hewbert »

I'm curious of how to do this. I would assume you could do it with substr(), but I'm not exactly sure. Basically, I want to snip the ending digits off an IP. So if the remote IP was 192.168.0.1, I'd like to snip the .1 off. Thanks in advance.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

e.g.

Code: Select all

<?php
$ip = '192.168.0.1';
$mask = substr($ip, 0, -strlen(strrchr($ip, '.')));
echo $mask;
?>
Post Reply