本文整理汇总了PHP中Codec::containsCharacter方法的典型用法代码示例。如果您正苦于以下问题:PHP Codec::containsCharacter方法的具体用法?PHP Codec::containsCharacter怎么用?PHP Codec::containsCharacter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Codec
的用法示例。
在下文中一共展示了Codec::containsCharacter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: whitelist
/**
* Returns the supplied input string after removing any characters not
* present in the supplied whitelist.
*
* @param string $input string input to be filtered.
* @param string $whitelist array or string of whitelist characters.
*
* @return string returns characters from $input that are present in $whitelist.
*/
public function whitelist($input, $whitelist)
{
// Sanity check
if (!is_string($input) || $input == '') {
$input = '';
}
if (is_string($whitelist)) {
$charEnc = Codec::detectEncoding($whitelist);
$limit = mb_strlen($whitelist, $charEnc);
$ary = array();
for ($i = 0; $i < $limit; $i++) {
$ary[] = mb_substr($whitelist, $i, 1, $charEnc);
}
$whitelist = $ary;
}
$filtered = '';
$initialCharEnc = Codec::detectEncoding($input);
$_4ByteCharacterString = Codec::normalizeEncoding($input);
$limit = mb_strlen($_4ByteCharacterString, 'UTF-32');
for ($i = 0; $i < $limit; $i++) {
$c = mb_substr($_4ByteCharacterString, $i, 1, 'UTF-32');
if (Codec::containsCharacter($c, $whitelist)) {
$filtered .= $c;
}
}
if ($filtered != '') {
$filtered = mb_convert_encoding($filtered, $initialCharEnc, 'UTF-32');
}
if (!is_string($filtered)) {
$filtered = '';
}
return $filtered;
}