note 101043 added to function.glob
| From: | reinhardatneidl dot net at osu1 dot php dot net | Date: | Mon, 22 Nov 2010 20:50:26 +0000 |
| Subject: | note 101043 added to function.glob | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174268@lists.php.net to get a copy of this message | ||
<?php
//A function to convert the glob pattern in a case insensitive version:
//SHORT: make glob() case insensitiv.
//sample call:
//$filelist = glob( '/path/*/'.globistr('*.PHP') ); //all *.php files in
subfolders
//sample call:
//$filelist = glob( dirname(__FILE__).'/'.globistr('*.JPG') );
//$filelist = array_merge($filelist,glob(
dirname(__FILE__).'/'.globistr('*.JPEG') ));
//$filelist = array_merge($filelist,glob(
dirname(__FILE__).'/'.globistr('*.gif') ));
//multibyte sample:
//$test = "mÄkAÃÃÃÃÃÃÐвÑÑÑал";
//$pattern = globistr($test,'UTF-8');
//RESULT: pattern:[mM][Ä
Ä][kK][aA]...
function globistr($string = '', $mbEncoding = ''/*optional
e.g.'UTF-8'*/){
//returns a case insensitive Version of the searchPattern for glob();
// e.g.: globistr('./*.jpg') => './*.[jJ][pP][gG]'
// e.g.: glob(dirname(__FILE__).'/'.globistr('*.jpg')) =>
'/.../*.[jJ][pP][gG]'
// known problems: globistr('./[abc].jpg') =>
FALSE:'./[[aA][bB][cC]].[jJ][pP][gG]'
//(Problem: existing Pattern[abc] will be overwritten)
// known solution: './[abc].'.globistr('jpg') => RIGHT:
'./[abc].[jJ][pP][gG]'
//(Solution: globistr() only caseSensitive Part, not everything)
$return = "";
if($mbEncoding !== ''){ //multiByte Version
$string = mb_convert_case($string,MB_CASE_LOWER,$mbEncoding);
}
else{ //standard Version (not multiByte,default)
$string = strtolower($string);
}
$mystrlen = strlen($string);
for($i=0;$i<$mystrlen;$i++){
if($mbEncoding !== ''){//multiByte Version
$myChar = mb_substr($string,$i,1,$mbEncoding);
//$myUpperChar = mb_strtoupper($myChar,$mbEncoding);
$myUpperChar = mb_convert_case($myChar,MB_CASE_UPPER,$mbEncoding);
}else{
$myChar = substr($string,$i,1);
$myUpperChar = strtoupper($myChar);
}
if($myUpperChar !== $myChar){ //there is a lower- and upperChar, / Char is case sentitive
$return .= '['.$myChar.$myUpperChar.']'; //adding both Versions : [xX]
}else{//only one case Version / Char is case insentitive
$return .= $myChar; //adding '1','.','*',...
}
}
return $return;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 79.209.115.161
----
Manual Page -- http://www.php.net/manual/en/function.glob.php
Edit -- https://master.php.net/note/edit/101043
Del: integrated -- https://master.php.net/note/delete/101043/integrated
Del: useless -- https://master.php.net/note/delete/101043/useless
Del: bad code -- https://master.php.net/note/delete/101043/bad+code
Del: spam -- https://master.php.net/note/delete/101043/spam
Del: non-english -- https://master.php.net/note/delete/101043/non-english
Del: in docs -- https://master.php.net/note/delete/101043/in+docs
Del: other reasons-- https://master.php.net/note/delete/101043
Reject -- https://master.php.net/note/reject/101043
Search -- https://master.php.net/manage/user-notes.php