Page 1 of 1

case insensitive file_exists()?

Posted: Mon Mar 31, 2003 5:38 pm
by MM Techniques
Is there a way to have the file_exists() function do a case insensitive search? I have alot of people who's links (either favorites or search engines) have all lowercased links. My site uses a simple include script like index.php?ServicePage=ClutchNew . If someone for say did a ServicePage=clutchnew I'd like the page to still display. Besides building an array with over a thousand values, one for each page; is there a way to do a case insensitive search? maybe something like:

---- Old Code

Code: Select all

if (eregi("%", $REQUEST_URI)){
$uri = urldecode(rawurldecode($REQUEST_URI));
header ("Location: http://www.mechanicmatt.com$uri");
}
else {}
$ServicePage = ereg_replace(".php", "", ereg_replace(".mm", "", $ServicePage));

if ($ServicePage == "" || !isset($ServicePage)){
$IncludeFile = "Main";
}
else if (file_exists("$ServicePage.php")){
$IncludeFile = "$ServicePage";
}
else{
    //if ($HTTP_REFERER == "" || eregi("unknown", $HTTP_REFERER)){
    urlencode(rawurlencode($REQUEST_URI));
    header("Location: http://www.mechanicmatt.com/MMIntelligence.php?RURI=$REQUEST_URI;$HTTP_REFERER");
    //}
    //else {
    //$IncludeFile = "e404";
    //}
}
To New Code...

Code: Select all

else if (strtolower(file_exists(strtolower("$ServicePage.php")))){
$IncludeFile = "$ServicePage";
}

Posted: Mon Mar 31, 2003 11:30 pm
by Tubbietoeter
If you work with unix I don't think this is possible ... since Unix just is case sensitive.
But you could give your pages numbers or name them all lowercase or you could realize a file_exists function of your own

but this:
if (strtolower(file_exists(strtolower("$ServicePage.php")))){
$IncludeFile = "$ServicePage";
}


won't work. Because what you do is you search for a lowercase filename which probably does not exist and change the return-value of the file_exists() function to lowercase.


you also could generate a mapping file which has as first parameter the lowercase filename like the one you get from the users an second parameter the filename for the file on the system (eg "lowercasefilename@FileNameInReal"). depending on names convention etc pp you could do an awk script that automatically generates the list every hour or so.

Posted: Tue Apr 01, 2003 2:26 am
by twigletmac
It is easiest if you have all of your page names as lowercase, that way you can just strtolower() the $ServicePage variable to do the check.

Mac