0

好的,我承认这是一个无聊的问题,但我找不到错误。

所以我的代码:

$this->table = array (
          "š" => "š",
          "Š" => "Š",
          "ý" => "ý",
          "Ý" => "Ý",
          "á" => "á",
          "Á" => "Á",
          "í" => "í",
          "Í" => "Í",
          "ú" => "ú",
          "Ú" => "Ú"
        );

$this->keyword = "š Č ú";

foreach ($this->table as $key => $value) {
                echo "key: ".$key." value ".$value." ";
                $this->keyword = str_replace($key, $value, $this->keyword);
            }

所以我想根据数组中的值替换 var 关键字中的特殊字符,但这不起作用。这部分脚本的输出是:

键: š 值 š 键: Š 值 Š 键: ý 值 ý ...

我究竟做错了什么?为什么值$key 与 相同$value

4

1 回答 1

2

使用htmlentitieson $value,否则实体(例如ú)将由浏览器呈现。

...
echo "key: ".$key." value ".htmlentities($value)." ";
...
于 2012-05-14T23:14:41.300 回答