PHP/String/eregi
Содержание
Case-insensitive Pattern Matching
<?php
$a = "UPPERCASE";
echo (int) ereg ("uppercase", $a);
echo "\n";
echo (int) eregi ("uppercase", $a);
echo "\n";
?>
eregi() function searches a string for another string.
Its syntax is: int eregi(string pattern, string string, [array regs])
<?
$password = "abc";
if (! eregi ("[[:alnum:]]{8,10}", $password)) :
print "Passwords must be from 8 through 10 characters in length.";
endif;
?>
eregi.php
<?php
$pswd = "asdf1asdf";
if (!eregi("^[a-zA-Z0-9]{8,10}$", $pswd))
echo "password must consist of alphanumeric characters, and must be 8-10 characters in length!";
?>
Getting the title of a remote page
<?php
$file = fopen("http://www.php.net/", "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof($file)) {
$line = fgets($file, 1024);
if (eregi("<title>(.*)</title>", $line, $out)) {
$title = $out[1];
break;
}
}
fclose($file);
?>