Snipping an IP Address
Moderator: General Moderators
Snipping an IP Address
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.
e.g.
Code: Select all
<?php
$ip = '192.168.0.1';
$mask = substr($ip, 0, -strlen(strrchr($ip, '.')));
echo $mask;
?>