简体   繁体   English

解码特殊字符...?

[英]Decode a special character...?

I am pulling through the field item_name from a database.我正在从数据库中提取字段 item_name。 It should read : "Reminisce Basic £11.99 + Card £4.99 + Free"它应该是:“Reminisce Basic £11.99 + Card £4.99 + Free”

But when its coming through the £ signs are coming out as is there a method to decode this to at least make it look like a £ sign?但是当它通过£符号出现时,是否有一种方法可以解码它以至少使它看起来像一个£符号?

My code is as follows :我的代码如下:

<?php
    $con = mysql_connect("localhost","","");
    mysql_select_db("", $con);

    $result = mysql_query("SELECT custom, item_name from paypalsub WHERE custom = '$_SESSION[uid]'");

    while($row = mysql_fetch_array($result))
    {
        $sub_type = $row['item_name'];
    }
?>
<h2>You are currently subscribed to : <?php echo ($sub_type); ?></h2>

The H2 is outputting it like this : H2 是这样输出的:

You are currently subscribed to : Reminisce Basic 11.99 + Card 4.99 + Free您当前订阅的是:Reminisce Basic 11.99 + Card 4.99 + Free

Any help.. Much appreciated.任何帮助.. 非常感谢。

Try with utf8_encode($string) or utf8_decode($string).尝试使用 utf8_encode($string) 或 utf8_decode($string)。 I never remember which one to use, sorry.我从来不记得用哪一个,抱歉。

1.) Are you sending the output in UTF-8? 1.) 您是否以 UTF-8 格式发送输出?

header('content-type: text/html; charset=utf-8')

2.) Have you also set the MySQL connection to UTF-8? 2.) 您是否也将 MySQL 连接设置为 UTF-8?

mysql_query("SET NAMES 'utf-8'");

It looks like your database is in some encoding (not UTF-8) and your output is in a different encoding.看起来您的数据库采用某种编码(不是 UTF-8),而您的输出采用不同的编码。

Find out which encoding the database uses.找出数据库使用的编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM