在html中以正确的编码显示文本

时间:2015-12-04 14:58:57

标签: php encoding html-entities

我正在尝试从我的数据库中获取一些数据(varchar)并在我的html中以正确的编码显示它们,因为它包含德语特殊字符。 数据库位于latin1_german2_ci(cp1252),我的html

<input type="text" id="owner" name="owner" value="<?=get_owner() ?>" class="form-control">
function get_owner()
{
    $owner = htmlentities($text_I_got_from_db, ENT_COMPAT, 'cp1252');
    return $owner;
}

这给了我,即。我的Kälte <input>,但我想要K&auml;lte。 我知道htmlentities()将特殊字符转换为htmlcode。我该怎么做才能在html中保持这种状态而不是“转换回”?

1 个答案:

答案 0 :(得分:0)

如果你想在页面中打印文字,那就是&#39;你可以使用这样的代码

    $owner = htmlentities('Kälte', ENT_COMPAT, 'UTF-8');
    echo htmlspecialchars($owner);