Php 将字符串从UTF-8解码到Windows1256
我有下面的代码,它试图将字符串从UTF转换为CP1256。我想将字符串解码为阿拉伯语,页面加密固定为UTF8Php 将字符串从UTF-8解码到Windows1256,php,utf-8,utf,Php,Utf 8,Utf,我有下面的代码,它试图将字符串从UTF转换为CP1256。我想将字符串解码为阿拉伯语,页面加密固定为UTF8 <?php $string = "ãÍãÏ Úæäí ãÍãæÏ Úáí"; $string = iconv("UTF-8//TRANSLIT//IGNORE", "Windows-1252//TRANSLIT//IGNORE", $string); echo $string; ?> $strings=“ÍÍÍÍÍÍÍÍÍÍÍÍÚáí”; setloca
<?php
$string = "ãÍãÏ Úæäí ãÍãæÏ Úáí";
$string = iconv("UTF-8//TRANSLIT//IGNORE", "Windows-1252//TRANSLIT//IGNORE", $string);
echo $string;
?>
$strings=“ÍÍÍÍÍÍÍÍÍÍÍÍÚáí”;
setlocale(LC_CTYPE,'nl_nl.UTF-8');
$convert=iconv('UTF-8','windows-1251//TRANSLIT//IGNORE',$strings);
echo var_dump($convert);
因此,您的阿拉伯语文本已在Windows-1256中编码,然后错误地编码到Windows-1252
如果源文件是UTF-8编码的,则答案是:
<?php
$string = "ãÍãÏ Úæäí ãÍãæÏ Úáí";
$string = iconv("UTF-8//TRANSLIT//IGNORE", "Windows-1252//TRANSLIT//IGNORE", $string);
# $string is now back to its 1256 encoding. Encode to UTF-8 for web page
$string = iconv("Windows-1256//TRANSLIT//IGNORE", "UTF-8//TRANSLIT//IGNORE", $string);
echo $string;
?>
如果源文件是“windows-1252”编码的,则必须使用:
<?php
$string = "ãÍãÏ Úæäí ãÍãæÏ Úáí";
# Interperate windows-1252 string as if it were windows-1256. Encode to UTF-8 for web page
$string = iconv("Windows-1256//TRANSLIT//IGNORE", "UTF-8//TRANSLIT//IGNORE", $string);
echo $string;
?>
如果您
$string
实际上来自数据库或文件,那么在应用任何转换之前,您必须确定源代码的编码。问题是什么?@Alastair McCormack我希望字符串以阿拉伯语显示,也就是说,源文件的编码是什么,你的代码像一个魔咒一样工作了几分钟,然后不知何故它停止了工作,我正在研究的真实示例可以在这个问题中找到,如果你想要PDF文件的副本,我可以上传它。