Alaa Gamal
Alaa Gamal

Reputation: 1135

strtolower fails with arabic characters

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 ø¹ù„ø§ø¡
?>

?>

Upvotes: 5

Views: 918

Answers (1)

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 174977

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 مصر
?>

Upvotes: 12

Related Questions