简体   繁体   English

htmlspecialchars使用非英语单词

[英]htmlspecialchars working with words not in english

I want to prevent from reading special chars, eg if $txt=" <b>hello</b> ", I want to print " <b>hello</b>" , and not " hello " with bold. 我想防止读取特殊字符,例如,如果$ txt =“ <b>hello</b> ”,我想打印“ <b>hello</b>" ,而不要用粗体打印“ hello ”。 So I added the line $txt=htmlspecialchars($txt, ENT_QUOTES, 'UTF-8'); 所以我添加了行$txt=htmlspecialchars($txt, ENT_QUOTES, 'UTF-8'); . It solved the problem, but now if I type words that not in english, eg שלום (hebrew word), it give me &#1513;&#1500;&#1493;&#1501; 它解决了问题,但是现在如果我输入不是英语的单词,例如שלום(希伯来语单词),它会给我&#1513;&#1500;&#1493;&#1501; . How do I solve it? 我该如何解决? This is my code: 这是我的代码:

$txt=$_POST['post_txt'];
$txt=htmlspecialchars($txt, ENT_QUOTES, 'UTF-8');/prevent xss
$txt=nl2br($txt);//make it with line breaks

I am not sure if Hebrew is supported, but these sites might clear your problem up. 我不确定是否支持希伯来语,但是这些站点可能会解决您的问题。 Also, htmlentities() should be used 另外,应使用htmlentities()

http://php.net/manual/en/function.htmlspecialchars.php http://php.net/manual/zh/function.htmlspecialchars.php

http://www.techiecorner.com/129/php-how-to-convert-iso-character-htmlentities-to-utf-8/ http://www.techiecorner.com/129/php-how-to-convert-iso-character-htmlentities-to-utf-8/

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM