GlobFileSuffix_ToExp_NoCase() - Create a 2-letter case-insensitive file suffix glob array for use in

This function is part of a solution when you want to use the PHP glob() function to return a list of files with a certain suffix, but you want the glob to perform matching in a case-insensitive manner.

Originally, I wrote this function, ... and ... on Linux, this works fine, but on Windows, the glob() function (using the GLOB_BRACE flag) will not handle this correctly (see PHP bug 69628).

As a result, we have to take a new approach using this function. Please read the info on that page for more info.


PHP Code

function GlobFileSuffix_ToExp_NoCase ($Suffix) {
	/*
	Purpose
		Used to create a case-insensitive glob subexpression from a specified file suffix.
	Parameters
		Suffix (string) = The file suffix we are building an expression with.
	Return
		Example: "jpg" returns "[jJ][pP][gG]"
	Version History
		1.0 2014.09.06 Tested by Russ Tanner on PHP 5.3.10.
	*/

	$r = ''; // Return buffer.
	$i = 0;

	// Iterate each character in the specified expression.
	for ($i; $i < strlen($Suffix); $i++) {
		// Get the current character.
		$char = substr($Suffix, $i, 1);
		// Build the expression and append it to the return buffer.
		$r .= '[' . strtolower($char) . strtoupper($char) . ']';
	}

	return $r;

}
 


The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)