-2
html_entity_decode()返回HTML实体,不是适用的字符。html_entity_decode()不起作用(PHP)
<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
<?php
$code='a'; // It's a code of 'a' UTF-8 character.
$char = html_entity_decode($code, ENT_COMPAT, $encoding = 'UTF-8');
/*
Now $char must contains 'a' value, but it contains 'a';
You can check this by following tests
*/
var_dump('a' === 'a'); // bool(false), of course.
var_dump('a' === $code); // bool(true)
var_dump('a' === $char); // bool(true) BUT MUST BE FALSE
var_dump($code === $char); // bool(true) BUT MUST BE FALSE
// Or this:
echo str_replace('&', '', $char); // it must print 'a', but it print '#97'
貌似这个函数什么也不做在我的情况。 有什么问题?
您的字符引用缺少分隔';':'a'。 – Gumbo 2014-12-13 12:27:47
PHP不是Python,它没有命名参数。 '$ encoding ='UTF-8''可能不会做你认为它的作用。函数调用应该是简单的'html_entity_decode($ code,ENT_COMPAT,'UTF-8')'。 – deceze 2014-12-13 12:33:00