本文整理汇总了PHP中InputFilter::character_entities_re方法的典型用法代码示例。如果您正苦于以下问题:PHP InputFilter::character_entities_re方法的具体用法?PHP InputFilter::character_entities_re怎么用?PHP InputFilter::character_entities_re使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InputFilter
的用法示例。
在下文中一共展示了InputFilter::character_entities_re方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _validate_entity
/**
* Callback function for strip_illegal_entities, do not use.
* @access private
* @param array $m matches
*/
public static function _validate_entity($m)
{
$is_valid = FALSE;
// valid entity references have the form
// /&named([;<\n\r])/
// for named entities, or
// /&#(\d{1,5}|[xX][0-9a-fA-F]{1,4})([;<\n\r])/
// for numeric character references
$e = trim($m[1]);
$r = $m[2];
if ($r == ';') {
$r = '';
}
if ($e[0] == '#') {
$e = strtolower($e);
if ($e[1] == 'x') {
$e = hexdec(substr($e, 2));
} else {
$e = substr($e, 1);
}
// numeric character references may only have values in the range 0-65535 (16 bit)
// we strip null, though, just for kicks
$is_valid = intval($e) > 0 && intval($e) <= 65535;
if ($is_valid) {
// normalize to decimal form
$e = '#' . intval($e) . ';';
}
} else {
if (self::$character_entities_re == '') {
self::$character_entities_re = ';(' . implode('|', self::$character_entities) . ');';
}
// named entities must be known
$is_valid = preg_match(self::$character_entities_re, $e, $matches);
// XXX should we map named entities to their numeric equivalents?
if ($is_valid) {
// normalize to name and nothing but the name... eh.
$e = $matches[1] . ';';
}
}
return $is_valid ? '&' . $e . $r : '';
}