PHP 8.5.0 Alpha 4 available for testing

Voting

: four plus two?
(Example: nine)

The Note You're Voting On

phlipping at yahoo dot com
22 years ago
you couls also try this function that I wrote before I found fnmatch:

function WildToReg($str)
{
$s = "";
for ($i = 0; $i < strlen($str); $i++)
{
$c = $str{$i};
if ($c =='?')
$s .= '.'; // any character
else if ($c == '*')
$s .= '.*'; // 0 or more any characters
else if ($c == '[' || $c == ']')
$s .= $c; // one of characters within []
else
$s .= '\\' . $c;
}
$s = '^' . $s . '$';

//trim redundant ^ or $
//eg ^.*\.txt$ matches exactly the same as \.txt$
if (substr($s,0,3) == "^.*")
$s = substr($s,3);
if (substr($s,-3,3) == ".*$")
$s = substr($s,0,-3);
return $s;
}

if (ereg(WildToReg("*.txt"), $fn))
print "$fn is a text file";
else
print "$fn is not a text file";

<< Back to user notes page

To Top