简体   繁体   中英

PHP: htmlentities and htmlspecialchars not converting some characters

I'm trying convert all special chars into HTML safe entities on their way into my database, but I can't seem to get PHP to handle certain characters. For example, if my string contains any of the following: ¡£¢∞§¶ It gets turned into an empty string.

So for example, the following string:

Hello£

Get turned into an empty string after it's POSTed and processed by the following code:

$workDetails["copy"] = htmlentities($workDetails["copy"], ENT_QUOTES, "UTF-8");

I presume I'm doing something wrong? :(

Maybe it will just be enough if you change the Encoding of your website to UTF-8 via the header() command:

header("Content-Type: text/html; charset=utf-8"); in PHP

or

<?xml version="1.0" encoding="utf-8" ?>; at the top of your HTML template if you use one.

but if you definitely need to convert those chars to its specific html code, you should create your own function to replace the symbols which are not covered by htmlspecialchars() as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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