|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-09-24 18:41 UTC] inge at upandforward dot com
Description:
------------
Array indexes, although they can be strings, are not allowed to contain national characters, even if encoded as UTF-8.
Thus, a string like "øvinger" becomes "vinger", and "Æsop" becomes "sop".
This is very unfortunate.
My example builds an array of "name only" indexes, all in lower case.
Each entry of the array contains the complete filename of the corresponding file.
This serves as a fast and relatively safe method to find the correct path to a file, regardless of case.
I tested using, among others, a file named "php/Øvinger.php".
DS is Directory Separator (/),
$filetypes is an array containing file types to search for (like "php")
lowercase and name_only should be self-explanatory.
Test script:
---------------
// First time only: Find all php files in
// the 'php', 'inc' and 'txt' directories.
if (!isset ($_SESSION['long']))
{ $_SESSION['long'] = array();
foreach ($filetypes as $dir)
{ $files = glob ($dir.DS."*.$dir");
// Save all info for each file. This means that we won't have to
foreach ($files as $file) // search any more.
{ $name = lowercase(name_only ($file));
$_SESSION['long'][$name] = $file;
}
}
}
Expected result:
----------------
$_SESSION['long']['øvinger'] contains "php/Øvinger"
Actual result:
--------------
$_SESSION['long']['vinger'] contains "php/Øvinger"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 15:00:01 2025 UTC |
I think I have found the problem, but no solution. The following test script functions perfectly when run stand-alone, but "basename" fails when run from Apache 2.0. Are you able to reproduce the error? <?php define ('PT' , '.'); // (Decimal) point define ('LF' , PHP_EOL); // File newline $charset = 'utf-8'; // NB! Select charset here! define ('CHARSET',$charset); // NB! Define it as a constant. setlocale(LC_ALL, 'nb_NO'); mb_internal_encoding (CHARSET); putenv ("LANG=nb_NO.".CHARSET); $filenames = array ("php/Treffer.php","php/Øvinger.php","php/Æsop.php"); $destinations = array(); // Save all info for each file. This means that we won't have to foreach ($filenames as $file) // search any more. { $key = basename($file,".php"); $destinations[$key] = $file; } echo "After: ".print_r($destinations); ?>For now I have made a work-around which works in all cases, using this function: function name_only($file) { $from[] = '.'.substr(strrchr($file,'.'),1); $from[] = dirname($file).'/'; // Remove extension and path. return str_replace ($from,'',$file); }