php页面无法识别“ø"来自 mysql 值 [英] Php page can't recognize "ø" from mysql value

查看:35
本文介绍了php页面无法识别“ø"来自 mysql 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字段 $name (varchar(128)) 其中有一个值Pølse Mand".

I have a field, $name (varchar(128)) in which there's a value "Pølse Mand".

现在我希望它在值为Pølse Mand"时打印一些特别的东西

Now I want it to print something special whenever the value is "Pølse Mand"

<?php 

if ($name=="Pølse Mand") { echo "123";};


?>

但由于某种原因,这不起作用.我还有另一个名为文本框"的值,当我用它做同样的事情时它工作正常,所以一定是ø"把事情搞砸了.

But for some reason this doesn't work. I also have another value named "Text box" and it works fine when I do the same with that, so it must be the "ø" that messes things up.

我认为我在 php 文件中的ø"与值中的 ø 有某种不同,尽管我已经尝试在 phpmyadmin 中直接逐个复制它.

I assume my "ø" in the php file is somehow different from the ø in the value, even though I've tried copying it directly letter for letter in phpmyadmin.

MySQL 连接排序规则为 utf8_unicode_ci,表中排序规则为 latin1_swedish_ci.我试过: <meta http-equiv="Content-Type" content="text/html; charset=utf8_unicode_ci"/> 和瑞典语,但它不起作用.

The MySQL connection collation is utf8_unicode_ci and the collation in the table is latin1_swedish_ci. I have tried: <meta http-equiv="Content-Type" content="text/html; charset=utf8_unicode_ci"/> and with the swedish one, but it just doesn't work.

推荐答案

您在客户端使用 UTF-8,因此必须告诉 MySQL 您使用 UTF-8.这是由 MySQL 命令 SET NAMES 'utf8' 完成的,它必须作为打开连接的第一个查询发送.根据您的安装和您在 PHP 脚本中使用的 MySQL 客户端库,这可以在每次连接时自动完成.

You're using UTF-8 on the client side so must tell MySQL that you use UTF-8. This is done by the MySQL command SET NAMES 'utf8' which must be send as the first query on opening a connection. Depending on your installation and on the MySQL client library you use in the PHP script this can be done automatically on each connect.

$mysqli = new mysqli("localhost", "user", "password", "db");
$mysqli->set_charset("utf8");

//

$mysql_set_charset("utf8");

这篇关于php页面无法识别“ø"来自 mysql 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆