phpcase-sensitivestrtr

OS-related strtr issue


I have this function that converts all special chars to uppercase:

function uc_latin1($str) {
    if(!defined("LATIN1_UC_CHARS"))
        define("LATIN1_UC_CHARS", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ");
    if(!defined("LATIN1_LC_CHARS"))
        define("LATIN1_LC_CHARS", "àáâãäåæçèéêëìíîïðñòóôõöøùúûüý");
    $str = strtoupper ( strtr ( $str, LATIN1_LC_CHARS, LATIN1_UC_CHARS ) );
    return $str;
}

This function works fine in my development PC which runs Windows XP... but, when I test it in the production server running Red Hat Linux, it does not uppercase the string. The string is ISO-8859-1 encoded.

How can I make it work in Linux too?


Solution

  • Have you tried using mb_strtoupper()? On my computer, this converts, at least, all of the characters you have defined although it may undesirably convert others as well.

    For example:

    $str = àáâãäåæçèéêëìíîïðñòóôõöøùúûüý;
    $str = mb_strtoupper($str);
    echo $str;
    // Prints ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ