PHP/String/eregi
Содержание
Case-insensitive Pattern Matching
<source lang="html4strict">
<?php
$a = "UPPERCASE"; echo (int) ereg ("uppercase", $a); echo "\n"; echo (int) eregi ("uppercase", $a); echo "\n";
?>
</source>
eregi() function searches a string for another string.
<source lang="html4strict">
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; ?>
</source>
eregi.php
<source lang="html4strict">
<?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!";
?>
</source>
Getting the title of a remote page
<source lang="html4strict">
<?php $file = fopen("http://www.php.net/", "r"); if (!$file) {
echo "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); ?> </source>