php htmlentities_decode,php编码问题htmlentities

我有用户输入并使用htmlentities()来转换所有实体.

但是,似乎有一些错误.当我输入

ääää öööö üüüü ääää

我明白了

ääää öööö üüüü ääää

看起来像这样

ääääöööööüüüüüüüääää

我究竟做错了什么?代码实际上只是这样:

$post=htmlentities($post);

编辑1

这里有一些我用于格式化的代码(它们有一些有用的功能):

//Secure with htmlentities (mysql_real_escape_string() comes later)

$post=htmlentities($post);

//Strip obsolete white spaces

$post = preg_replace("/ +/", " ", $post);

//Detect links

$pattern_url='~(?>[a-z+]{2,}://|www\.)(?:[a-z0-9]+(?:\.[a-z0-9]+)?@)?(?:(?:[a-z](?:[a-z0-9]|(?|\n]*[a-z0-9])*/?(?:\?[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?(?:&[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?)*)?(?:#[a-z0-9_%.]+)?~i';

preg_match_all($pattern_url, $post, $matches);

for ($i=0; $i < count($matches[0]); $i++)

{

if(substr($matches[0][$i],0,4)=='www.')

$post = str_replace($matches[0][$i],'http://'.$matches[0][$i],$post);

}

$post = preg_replace($pattern_url,'\\0',$post);

//Keep line breaks (more than one will be stripped above)

$post=nl2br($post);

//Remove more than one linebreak

$post=preg_replace("/(
\s*)+/", "
", $post);

//Secure with mysql_real_escape_string()

$post=mysql_real_escape_string($post);

解决方法:

您必须手动指定htmlentities()的编码(UTF-8):

echo htmlentities("ääää öööö üüüü ääää", null, "UTF-8");

输出:

ääää öööö üüüü ääää

标签:php,encoding

来源: https://codeday.me/bug/20191007/1866764.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值