本文整理匯總了PHP中PKPString::utf8_is_valid方法的典型用法代碼示例。如果您正苦於以下問題:PHP PKPString::utf8_is_valid方法的具體用法?PHP PKPString::utf8_is_valid怎麽用?PHP PKPString::utf8_is_valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PKPString
的用法示例。
在下文中一共展示了PKPString::utf8_is_valid方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: cleanVar
/**
* Sanitize a variable.
* Removes leading and trailing whitespace, normalizes all characters to UTF-8.
* @param $var string
* @return string
*/
static function cleanVar($var)
{
// only normalize strings that are not UTF-8 already, and when the system is using UTF-8
if (Config::getVar('i18n', 'charset_normalization') == 'On' && strtolower_codesafe(Config::getVar('i18n', 'client_charset')) == 'utf-8' && !PKPString::utf8_is_valid($var)) {
$var = PKPString::utf8_normalize($var);
// convert HTML entities into valid UTF-8 characters (do not transcode)
$var = html_entity_decode($var, ENT_COMPAT, 'UTF-8');
// strip any invalid UTF-8 sequences
$var = PKPString::utf8_bad_strip($var);
$var = htmlspecialchars($var, ENT_NOQUOTES, 'UTF-8', false);
}
// strip any invalid ASCII control characters
$var = PKPString::utf8_strip_ascii_ctrl($var);
return trim($var);
}