Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

str_replace don't work for some chars

I wrote below code but it works wrong:

$t = "۰۱۲۳۴۵۶۷۸۹٤٥٦";
$correct = array("0","1","2","3","4","5","6","7","8","9","4","5","6");
$wrong = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩","۴","۵","۶");
echo $t = str_replace($wrong,$correct, $t);

and the result isn't right

۰۱۲۳456۷۸۹۰۱۲۳456۷۸۹456

I search in stack and same questions and it's answers don't help me.

like image 754
Ehsan Avatar asked Aug 14 '26 19:08

Ehsan


1 Answers

Use this code:-

$t = "۰۱۲۳٤٥٦";
$text = preg_replace(
            array("٠","١","٢","٣","٤","٥","٦",),
            array("0","1","2","3","4","5","6",),
            $t );
like image 62
Rakesh Kumar Avatar answered Aug 17 '26 12:08

Rakesh Kumar