开发者

Php page can't recognize "ø" from mysql value

I have a field, $name (varchar(128)) in which there's a value "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.

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 phpmya开发者_开发问答dmin.

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.


Are you using MySql or MySqli?

For MySQL use this code before the request:

mysql_set_charset ( 'latin7' );

or:

mysql_set_charset ( 'utf8' );

And for MySQLi:

$mysqli -> set_charset ( 'latin7' ); //Change $mysqli to your variable name

or:

$mysqli -> set_charset ( 'utf8' );

As for the <meta> tag, use:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

or:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-13"/>

Try both options and find which works best for you.


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");


try to change table encoding to utf8 and after mysql connection run query: set names utf8

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜