【问题标题】:Non-ascii characters stops mysql statement非 ascii 字符停止 mysql 语句
【发布时间】:2012-04-25 22:29:09
【问题描述】:

此 SQL 失败。

SQL 是

INSERT INTO
    `migration_loose_terms`
    (`source`,`field`,`term`,`lastaccess`)
VALUES
    ('services.media','keywords','spermatozoïde','2012-04-25 12:00:00')

因为它包含一个奇怪的(ï) 字符。

你在 php/mysql 中使用什么函数来清除要被剥离的 nonascii 字符或以某种方式使该词进入 mysql?

【问题讨论】:

  • 我确保一切都使用 UTF-8:我的表、PHP-MySQL 连接、PHP 内、浏览器内...
  • 像这样;不正确的字符串值:第 1 行的列 'term' 的 '\xEFde'
  • for where 语句总是在您要查找的值前面使用 N 例如:select value from table where value = N'value';

标签: php mysql sql non-ascii-characters


【解决方案1】:

如果要去除非 ASCII 字符,可以使用以下代码:

<?php
$input = "Clean the non ASCII äócharacters.";
$output = preg_replace('/[^(\x20-\x7F)]*/','', $input);
echo $output;
?>

否则,您是否尝试使用 mysql_real_escape_string 将相关单词换行?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 2015-01-06
    • 2015-04-10
    • 1970-01-01
    • 2016-12-09
    相关资源
    最近更新 更多