Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strtolower fails with arabic characters

Tags:

php

my site is allow users to register with arabic/english names

i am trying to convert user first and last name to lower case

i am using this function

$first_name = strtolower ( $_POST['first_name'] );

if i try to put arabic name i get this encode ( ø¹ù„ø§ø¡ )

try it by your self

<?
echo 'مصر'; // return مصر
echo strtolower('مصر'); // return ø¹ù„ø§ø¡
?>

?>

like image 816
Alaa Gamal Avatar asked Dec 20 '22 21:12

Alaa Gamal


1 Answers

You can't use strtolower on UTF-8 encoded string, only on ISO 8859-1. Use mb_strtolower() instead. You also need to specify the encoding used, make sure it's set correctly (probably "UTF-8").

<?
echo 'مصر'; // return مصر
echo mb_strtolower('مصر', 'UTF-8'); // return مصر
?>
like image 69
Madara's Ghost Avatar answered Jan 06 '23 16:01

Madara's Ghost