Page 1 of 1

Snipping an IP Address

Posted: Mon Feb 03, 2003 8:39 am
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.

Posted: Mon Feb 03, 2003 9:29 am
by volka
e.g.

Code: Select all

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