UTF8 到 CP1255 转换

问题描述 投票:0回答:2

我正在尝试将 UTF-8 字符串转换为 CP1255(希伯来语)

我尝试运行以下命令(我正在使用 detector_encoding,因为我的一些输入不是 UTF-8):

foreach($param as $key=>$value){
    $newval = iconv(mb_detect_encoding($value),"cp1255",$value);
    $querystr .= $key."=".$newval."&";
}

无论如何,结果是所有希伯来字符都返回漂亮的 � 符号, 所有其他(英语/数字)均按预期并保持不变。

我怎样才能正确地做到这一点?

php utf-8 character-encoding iconv
2个回答
6
投票

我找到了解决办法:

foreach($param as $key=>$value){
    $value_encoding = mb_detect_encoding($value);
    if($value_encoding == "UTF-8"){
        $newval = iconv($value_encoding,"cp1255",$value);
    }else{
        $newval = $value;
    }
    $endpoint = add_query_arg($key,$newval,$endpoint);
}

$content = file_get_contents($endpoint);

0
投票

E��h�}����r�5���n� ( L-mģR�6Y3 \S�t� ��^��ʰ׶�㸵� )������Rf ���[!10�T����([+@�����P�J�[�}V�Y� ��9�#�(;�+�֜7vquBM�{͔� �1?��)��d�ZetF�h���5���� ��?b�\��ר� R��sJF�@�Z �R$E��6 M (�h��c�/w��w<

**

�m�~,

enter code here
�Vo2�5;�B�����.�ϭRMsGt%S�1�]t����Vm��{m�~J]����|�8]L-k �튮�7���_�I����r�v耮

© www.soinside.com 2019 - 2024. All rights reserved.