2

I've a php page that return a string in persian , this is the content I have now :

    ÙØ±ÙˆØ´Ú¯Ø§Ù‡ تعطیل Ù…ÛŒ باشد .
ساعت کاری ÙØ±ÙˆØ´Ú¯Ø§Ù‡ 8 الی 22 
روزهای شنبه تا پنج شنبه

as you can see, the encoding is wrong and it's not readable ,I need to convert it to utf-8 encoding . I'm returning the data from database, encoding of table and cell in database is utf8_persian_ci and it's shows currency in phpmyadmin .

How can I convert this non readable string to utf-8 encoding and make it readable ? I've tried utf8-encoding and below code but non of them works :

    echo iconv(mb_detect_encoding($string, mb_detect_order(), true), "UTF-8", $string);

How can I fix this ?

Navid Abutorab
  • 1,667
  • 7
  • 31
  • 58

2 Answers2

1

you can try this function:

public function content_iconv($data, $to = 'utf-8') {
    $encode_array = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP');
    $encoded = mb_detect_encoding($data, $encode_array);
    $to = strtoupper($to);
    if($encoded != $to) {
        $data = mb_convert_encoding($data, 'utf-8', $encoded);
    }
    return $data;
}
Genuine
  • 264
  • 1
  • 7
-1

Do not use any conversion subroutines. Fix the program.

The output is "Mojibake" for some Arabic text. See the discussion of such here .

For how to fix the data (unless you choose to reload it), see this.

Rick James
  • 135,179
  • 13
  • 127
  • 222