编码不合适的字符

时间:2012-12-24 14:30:37

标签: php encoding utf-8 decoding utf8-decode

我怎样才能将它打印成代码中的内容? ışık hğzmesi是在代码中编写的,我希望它再次打印为ışık hğzmesi。我在下面尝试过的utf-8编码他们没有用。我的代码编辑器设置也是utf-8。

<?php
    $t = 'ışık hğzmesi';
    echo utf8_encode($t);

result:ışık hğzmesi
?>


<?php
    $t = 'ışık hüzmesi';
    echo utf8_decode(($t));

//result:???k hüzmesi
?>

<?php
    $t = 'ışık hüzmesi';
    echo urlencode($t);

//result:%C4%B1%C5%9F%C4%B1k+h%C3%BCzmesi
?>


<?php
    $t = 'ışık hüzmesi';
    echo urldecode(urlencode($t));

//result:ışık hüzmesi
?>

2 个答案:

答案 0 :(得分:1)

源文件的物理编码是UTF-8,因此字符串已经是UTF-8。切勿使用utf8_encode

<?php
header("Content-Type: text/html; charset=UTF-8");
$t = 'ışık hğzmesi';
echo $t;

答案 1 :(得分:0)

将此作为代码中的第一件事:

header('Content-Type: text/html; charset=utf-8');