Last active
February 3, 2025 19:37
-
-
Save gecon/3dfe1ff6baa1e646b170 to your computer and use it in GitHub Desktop.
uppercase greek without accents (php solution)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*********************************************************************** | |
A simple PHP function that will correctly uppercase Greek language | |
with proper spelling rules (removing accents in uppercased letters). | |
This is a server-side alternative to CSS uppercase() for Greek. | |
Greek CSS uppercase() is not working right on some browsers. | |
You can fix this by using javascript (increases browser load time) or | |
in server side by using this function here. | |
(function does not differentiate simple eta "η" to disjunctive eta "ή") | |
Author: Giannis Economou | 4-Mar-2016 | |
Last meaningful update: Mar-2017 | |
***********************************************************************/ | |
function uc_without_accents($string, $enc = "utf-8") { | |
return strtr(mb_strtoupper($string, $enc), | |
array('Ά' => 'Α', 'Έ' => 'Ε', 'Ί' => 'Ι', 'Ή' => 'Η', 'Ύ' => 'Υ', | |
'Ό' => 'Ο', 'Ώ' => 'Ω', 'A' => 'A', 'A' => 'A', 'A' => 'A', 'A' => 'A', | |
'Y' => 'Y','ΐ' => 'Ϊ' | |
)); | |
} | |
?> | |
<?php | |
$test = "Ελάτε να φάτε τα καλύτερα παϊδάκια, Μαΐου, τρόλεϊ, Το ένα ή το άλλο."; | |
echo $test ."\n"; | |
echo "Uppercase: " . uc_without_accents($test) ."\n"; | |
?> |
$test = "Ελάτε να φάτε τα καλύτερα παϊδάκια, Μαΐου, τρόλεϊ, Το ένα ή το άλλο.";
Ότι καλύτερο σε test var έχω δει εδώ και καιρό.
Ευχαριστώ <3
Great solution mate! Ευχαριστούμε πάρα πολύ!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Συγνώμη που ρωτάω, τα παϊδάκια είναι αρνίσια ή χοιρινά; Με έκανες να πεινάσω πρωί πρωί... 😄
Ευχαριστώ για τον κώδικα σου! Καλή όρεξη!