所以我的代码:
$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
相同?
答案 0 :(得分:2)
在$value
上使用htmlentities
,否则该实体(例如ú
)将由浏览器呈现。
...
echo "key: ".$key." value ".htmlentities($value)." ";
...