---------------------------------------------------
| Date: 2003-02-17 00:24:06 |
| Filename: ereg.php |
| Author: detour@metalshell.com |
| |
| http://www.metalshell.com/ |
---------------------------------------------------
');
else
echo('CAT not found.
');
// eregi() is case insensitive so dog is found
if( eregi("dog", $str1) )
echo('dog found.
');
else
echo('dog not found.
');
// Replace 'mouse' with 'cat'
if( $str1 = ereg_replace("mouse", "CAT", $str1) )
echo('mouse replaced with cat
');
else
echo('mouse not found.
');
echo('$str1 now equals "' . $str1 . '"
');
// Case insensitive replace
if( $str1 = eregi_replace("cat", "mouse", $str1) )
echo('cat and CAT replace with mouse
');
else
echo('no match for cat
');
echo('$str1 now equals "' . $str1 . '"
');
// Cycle through the ip array and test each one
foreach ($ipnum as $ipn) {
if(valid_ip($ipn))
echo("$ipn is a valid ip.
");
else
echo("$ipn is an invalid ip.
");
}
// Takes an ip as an arg and tests to see if it is valid
function valid_ip($ip) {
if( ereg( "^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$", $ip, $res ) ) {
for($x = 1; $x < 5; $x++)
if($res[$x] > 255)
return FALSE;
} else {
return FALSE;
}
return TRUE;
}
?>