我寫了下面的代碼工作,但它的工作原理錯誤:str_replace函數不對某些字符
$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);
,結果是不正確的
۰۱۲۳456۷۸۹۰۱۲۳456۷۸۹456
我在堆棧和相同的問題,搜索和它的答案不幫助我。
這段代碼很慢。每個if語句都會運行'substr()'函數,當有一個很長的for循環和這麼多'substr'函數時,你的代碼將會非常慢!如果你想使用這種方法,最好有一個開關(http://nl3.php.net/manual/en/control-structures.switch.php)。這又是,不建議。儘管我不會低估它,因爲它有幫助,但也不是那麼好。 – Jelmer
是的,你是對的!代碼太重且太慢,但它是面對一段替代HTML代碼時最靈活的代碼。 –
我想將它與其相反,我想將波斯語數字轉換爲拉丁語,所以我將它更改爲'if (substr($ srting,$ sub,2)==「$ num8」)$ stringtemp。= 8;'因爲unicodes得到2字節 – Ehsan