9

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.

Eloims
  • 5,106
  • 4
  • 25
  • 41
Pavlen
  • 129
  • 1
  • 12
  • 4
    Try `mb_strtoupper('YOUR TEXT', 'UTF-8')` –  Dec 31 '13 at 10:02
  • If your example doesn't work, when it should, then you probably have some encoding issues. See this > http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Glavić Dec 31 '13 at 10:14
  • Plus, your function is `strtoUPPER`, but you are converting uppercase to lowercase, like `"Š" => "š"` etc. Your [function](https://eval.in/84338) should work. What is the exact problem? – Glavić Dec 31 '13 at 10:23
  • Now work, your example :) – Pavlen Dec 31 '13 at 14:20

3 Answers3

4

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 ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ ΒΑΦΉΣ ΨΗΜΈΝΗ ΓΗ, ΔΡΑΣΚΕΛΊΖΕΙ ΥΠΈΡ ΝΩΘΡΟΎ ΚΥΝΌΣ
?>
Eloims
  • 5,106
  • 4
  • 25
  • 41
1

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 ščćžđ ŠČĆŽĐ');
Community
  • 1
  • 1
rullof
  • 7,124
  • 6
  • 27
  • 36
0

Here is the answer... Edit your php script and add function like this: 1:

function sumniki($string)
{ 
$sumniki = array("ć", "Ć", "č", "Č", "š", "Š", "ž", "Ž"); 
$koda = array("&#263;", "&#264;", "&#269;", "&#268;", "&#154;", "&#138;", "&#158;", "&#142;"); 

$nova = str_replace($sumniki, $koda, $string); 
return $nova; 
}

2: add "sumniki" to your code like this

$name = sumniki($_POST['name']);
$email = sumniki($_POST['email']); 

and so on if you have more...

Elis Sabic
  • 11
  • 3