【问题标题】:HTML Special Characters Post as ASCIIHTML 特殊字符以 ASCII 格式发布
【发布时间】:2017-02-28 08:04:29
【问题描述】:

请原谅我,我是新来的。我希望我的格式正确。我已将数据库从 ASCII 转换为 UTF-8,更改了所有特殊字符。 Example â changed to â

工作示例: 乔治·德沃格伯爵庄园

改为,

Domaine Comte Georges de Vogüé

在我的 HTML 页面中,我有一个表单,下面的行作为选项之一。

<option>Domaine Comte Georges de Vog&uuml;&eacute;</option>

当表单发布到 PHP 页面时,该值更改为

Domaine Comte Georges de Vogüé

所以当它在数据库中搜索时当然找不到。

下拉字段的选项是使用我在 [So You Need To Fill a Dropdown Dynamically https://css-tricks.com/dynamic-dropdowns/]] 找到的代码动态生成的

如何防止选项值在发布到 PHP 脚本时发生变化?

【问题讨论】:

标签: php html utf-8 ascii


【解决方案1】:

您是否尝试为选项设置值?

<option value="Domaine Comte Georges de Vog&uuml;&eacute;">Domaine Comte Georges de Vog&uuml;&eacute;</option>

【讨论】:

    【解决方案2】:

    在执行数据库搜索之前,您需要将页面上显示的 HTML 实体(ü、é 等)转换为其代表值;这可以使用 PHP 函数 html_entity_decode() 来完成——例如:

    <?php
    print html_entity_decode('Domaine Comte Georges de Vog&uuml;&eacute;');
    ?>
    

    将导致输出 --

    Domaine Comte Georges de Vogüé

    更多信息、选项和使用示例可以在 PHP 手册中找到 -- http://php.net/manual/en/function.html-entity-decode.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多