本文整理匯總了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 : '';
}