Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Upper Serbian letters, Č,Ć,Š,Đ,Ž in PHP

Tags:

php

I got a problem to make upper letters in php.

I tried this function:

function strtouper_srbija($string) {
    $low=array("č" => "Č", "ž" => "Ž", "Š" => "š","Đ" => "đ","Č" => "č");
    return strtoupper(strtr($string,$low));
}

and tried to use with some POST data from html page,text filed,but no succes,so if you have solutions,will be fine..

Also, I found solution with CSS, with text-transform: uppercase;, but will be fine to have PHP example.

like image 656
Pavlen Avatar asked Dec 31 '13 09:12

Pavlen


2 Answers

Couldn't you use mb_strtoupper?

http://www.php.net/manual/en/function.mb-strtoupper.php

<?php
$str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
$str = mb_strtoupper($str, 'UTF-8');
echo $str; // Prints ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ ΒΑΦΉΣ ΨΗΜΈΝΗ ΓΗ, ΔΡΑΣΚΕΛΊΖΕΙ ΥΠΈΡ ΝΩΘΡΟΎ ΚΥΝΌΣ
?>
like image 99
Eloims Avatar answered Oct 01 '22 15:10

Eloims


Loop trough your string using a foreach loop:

function strtouper_srbija($string) {
    $letters = array("č" => "Č", "ž" => "Ž", "š" => "Š", "đ" => "Đ", "ć" => "Ć");
    $newString = $string;
    foreach ($letters as $lower=>$upper){
        $newString = str_replace($lower, $upper, $newString);
    }
    return $newString;
    }

Other way from Glavić

function strtouper_srbija($string) {
    $letters = array("č" => "Č", "ž" => "Ž", "š" => "Š", "đ" => "Đ", "ć" => "Ć");
    return str_replace(array_keys($letters), array_values($letters), $string);
}

echo strtouper_srbija('testiram ščćžđ ŠČĆŽĐ');
like image 42
rullof Avatar answered Oct 01 '22 16:10

rullof