'); else echo('CAT not found.
'); // pregi() is case insensitive so dog is found if( pregi("DOG", $str1) ) echo('dog found.
'); else echo('dog not found.
'); // Replace 'mouse' with 'cat' if( $str1 = preg_replace("mouse", "CAT", $str1) ) echo('mouse replaced with cat
'); else echo('mouse not found.
'); echo('$str1 now equals "' . $str1 . '"
'); // Case insensitive replace if( $str1 = pregi_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( preg( "^([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; } ?>