php 在php中将latin1字符串转换为utf8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12939075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:31:00  来源:igfitidea点击:

convert latin1 string to utf8 in php

php

提问by aLFaRSi

Possible Duplicate:
Convert utf8-characters to iso-88591 and back in PHP

可能的重复:
将 utf8 字符转换为 iso-88591 并在 PHP 中返回

i have this php file that connect to my MySQL BD , the BD callation is latin1_swedish_ci

我有这个连接到我的 MySQL BD 的 php 文件,BD 调用是 latin1_swedish_ci

this is my php code :

这是我的 php 代码:

<?php

$con = mysql_connect("localhost","root","");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("ttbfb", $con);

$result = mysql_query("SELECT * FROM news");

while($row = mysql_fetch_array($result)) {

    echo $row['name'];

}

mysql_close($con);
?>

how can i convert the $row['name'] string into utf8 before i get the echo ?

在得到回声之前,如何将 $row['name'] 字符串转换为 utf8 ?