每当使用£时,MySQL或PHP都附加一个 [英] MySQL or PHP is appending a  whenever the £ is used

查看:88
本文介绍了每当使用£时,MySQL或PHP都附加一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提供的答案都很棒,我在Alnitak的回答中提到,我需要去看看我的CSV生成脚本,因为无论什么原因,它没有输出UTF-8。

Answers provided have all been great, I mentioned in the comments of Alnitak's answer that I would need to go take a look at my CSV Generation script because for whatever reason it wasn't outputting UTF-8.

正如已经正确指出的,它输出UTF-8 - Ye Olde Microsoft Excel存在的问题,它不是我想要的编码方式。

As was correctly pointed out, it WAS outputting UTF-8 - the problem existed with Ye Olde Microsoft Excel which wasn't picking up the encoding the way I would have liked.

我现有的CSV一代看起来像:

My existing CSV generation looked something like:

// Create file and exit;
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
echo $csv_output;

现在看起来像:

// Create file and exit;
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: text/csv; charset=ISO-8859-1");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");

echo iconv('UTF-8', 'ISO-8859-1', $csv_output);



--------------------- ----------------------------------



ORIGINAL QUESTION

您好,

我有一个表单收集数据,表单工作确定,但我只是注意到,如果有人类型或使用'£'符号,MySQL数据库最终以'£'。

I've got a form which collects data, form works ok but I've just noticed that if someone types or uses a '£' symbol, the MySQL DB ends up with '£'.

在何处或如何阻止此情况发生,代码和数据库信息如下:

Not really sure where or how to stop this from happening, code and DB information to follow:

MySQL详细信息

mysql> SHOW COLUMNS FROM fraud_report;
+--------------+--------------+------+-----+---------+----------------+
| Field        | Type         | Null | Key | Default | Extra          |
+--------------+--------------+------+-----+---------+----------------+
| id           | mediumint(9) |      | PRI | NULL    | auto_increment |
| crm_number   | varchar(32)  | YES  |     | NULL    |                |
| datacash_ref | varchar(32)  | YES  |     | NULL    |                |
| amount       | varchar(32)  | YES  |     | NULL    |                |
| sales_date   | varchar(32)  | YES  |     | NULL    |                |
| domain       | varchar(32)  | YES  |     | NULL    |                |
| date_added   | datetime     | YES  |     | NULL    |                |
| agent_added  | varchar(32)  | YES  |     | NULL    |                |
+--------------+--------------+------+-----+---------+----------------+
8 rows in set (0.03 sec)

PHP功能

function    processFraudForm($crm_number, $datacash_ref, $amount, $sales_date, $domain, $agent_added) {

    // Insert Data to DB
    $sql    = "INSERT INTO fraud_report (id, crm_number, datacash_ref, amount, sales_date, domain, date_added, agent_added) VALUES (NULL, '$crm_number', '$datacash_ref', '$amount', '$sales_date', '$domain', NOW(), '$agent_added')";
    $result = mysql_query($sql) or die (mysql_error());

    if ($result) {
        $outcome = "<div id=\"success\">Emails sent and database updated.</div>";
    } else {
        $outcome = "<div id=\"error\">Something went wrong!</div>";
    }

    return $outcome;
}

示例数据库条目

+----+------------+--------------+---------+------------+--------------------+---------------------+------------------+
| id | crm_number | datacash_ref | amount  | sales_date | domain             | date_added          | agent_added      |
+----+------------+--------------+---------+------------+--------------------+---------------------+------------------+
| 13 | 100xxxxxxx | 10000000     | £10.93 | 18/12/08   |  blargh.com        | 2008-12-22 10:53:53 | agent.name | 


推荐答案

您看到的是 UTF-8 encoding - 这是一种以相对紧凑的格式存储Unicode字符的方式。

What you're seeing is UTF-8 encoding - it's a way of storing Unicode characters in a relatively compact format.

在Unicode中,井号符号具有值 0x00a3 ,但是当它以UTF-8编写时变为 0xc2 0xa3 这是数据库中存储的内容。看来您的数据库表已设置为使用UTF-8编码。

The pound symbol has value 0x00a3 in Unicode, but when it's written in UTF-8 that becomes 0xc2 0xa3 and that's what's stored in the database. It seems that your database table is already set to use UTF-8 encoding. This is a good thing!

如果你从数据库中取回值,并显示在UTF-8兼容终端上(或在声明为UTF-8编码的网页上),它将再次看起来像一个正常的井号。

If you pull the value back out from the database and display it on a UTF-8 compatible terminal (or on a web page that's declared as being UTF-8 encoded) it will look like a normal pound sign again.

这篇关于每当使用£时,MySQL或PHP都附加一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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