我正在尝试创建一个接受htmlspecialchars参数的简单方法.虽然我正在获得
PHP通知:
Use of undefined constant ENT_HTML5 – assumed ‘ENT_HTML5’
任何可能导致这种情况的想法?
/ **
* Encode string.
*
* @param array/string $value
* @param string $param
* @return string
*/
protected function escape($mixed, $params) {
$defaults = array('flags' => ENT_QUOTES | ENT_HTML5, 'charset' => 'UTF-8');
$params = array_merge($defaults, $params);
if (is_array($mixed)) {
foreach($mixed as $key => $value) {
$mixed[$key] = $this->escape($value, $params['flags'], $params['charset']);
}
} elseif (is_string($mixed)) {
$mixed = htmlspecialchars($mixed, $params['flags'], $params['charset']);
}
return $mixed;
}
>如果我更改:ENT_QUOTES | ENT_HTML5进入:ENT_QUOTES,我收到一个不同的错误
Warning: htmlspecialchars() expects parameter 2 to be long, string
given
UPDATE
我使用PHP 5.3,这是HTML5错误的原因.如果我更改ENT_QUOTES | ENT_HTML5到ENT_COMPAT | ENT_HTML401我得到同样的错误:
Notice: Use of undefined constant ENT_HTML401 – assumed ‘ENT_HTML401’