My guess is you are looking for preg_match which uses regular expressions to parse strings. it returns the number of matches it finds, and if you provide the optional 3rd argument, will toss the matches into that variable as an array so you can reference them later.
Some basic info on the php.net website about regular expression syntax is here. Regular expressions are amazing little beasts - well worth the trouble to get to know them. 😉
I came up with a pattern that I think will match what you need, but i wrapped a loop around it with an array of some play IP addresses so you can test it to make sure it catches everything you want to catch. then you can just pick out the parts of the code you really need.
Hope this helps you out a bit!
$ips[] = $_SERVER["REMOTE_ADDR"]; // will match
$ips[] = "666.555.4.23sw35"; // will match (didn't restrict anything on the last set of numbers)
$ips[] = "1.6.2.23"; // will match
$ips[] = "45.234.24.234"; // will match
$ips[] = "1924.168.1.11223"; // won't match
$ips[] = "192.168.1a"; // won't match
$ips[] = "192.1a68.1.23"; // won't match
$ips[] = "192..168.1.23"; // won't match
// pattern using regular expresions -
// will match any string that starts with
// 1-3 digits then a '.', 1-3 digits then a '.', then 1-3 more digits then a '.'
$pattern = "/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\./";
foreach($ips as $ip)
{
if (!preg_match($pattern, $ip, $matches))
{
print "I don't understand your ip address! '$ip'<br>";
continue;
}
// will print the part that matched (should only be one)
print "matched: " . $matches[0] . "<br>";
}