本文整理汇总了PHP中UTF8::wpstrlen方法的典型用法代码示例。如果您正苦于以下问题:PHP UTF8::wpstrlen方法的具体用法?PHP UTF8::wpstrlen怎么用?PHP UTF8::wpstrlen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTF8
的用法示例。
在下文中一共展示了UTF8::wpstrlen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: email
/**
* Check an email address for correct format.
*
* @link http://www.iamcal.com/publish/articles/php/parsing_email/
* @link http://www.w3.org/Protocols/rfc822/
*
* @param string $email email address
* @param boolean $strict strict RFC compatibility
* @return boolean
*/
public static function email($email, $strict = FALSE)
{
if (UTF8::wpstrlen($email) > 254) {
return FALSE;
}
if ($strict === TRUE) {
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$pair = '\\x5c[\\x00-\\x7f]';
$domain_literal = "\\x5b({$dtext}|{$pair})*\\x5d";
$quoted_string = "\\x22({$qtext}|{$pair})*\\x22";
$sub_domain = "({$atom}|{$domain_literal})";
$word = "({$atom}|{$quoted_string})";
$domain = "{$sub_domain}(\\x2e{$sub_domain})*";
$local_part = "{$word}(\\x2e{$word})*";
$expression = "/^{$local_part}\\x40{$domain}\$/D";
} else {
$expression = '/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\\.[a-z]{2,6}|\\d{1,3}(?:\\.\\d{1,3}){3})$/iD';
}
return (bool) preg_match($expression, (string) $email);
}
示例2: str_pad
/**
* Pads a UTF-8 string to a certain length with another string. This is a
* UTF8-aware version of [str_pad](http://php.net/str_pad).
*
* $str = UTF8::wpstr_pad($str, $length);
*
* @author Harry Fuecks <hfuecks@gmail.com>
* @param string $str input string
* @param integer $final_str_length desired string length after padding
* @param string $pad_str string to use as padding
* @param string $pad_type padding type: STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH
* @return string
*/
public static function str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
if (UTF8::is_ascii($str) and UTF8::is_ascii($pad_str)) {
return str_pad($str, $final_str_length, $pad_str, $pad_type);
}
$str_length = UTF8::wpstrlen($str);
if ($final_str_length <= 0 or $final_str_length <= $str_length) {
return $str;
}
$pad_str_length = UTF8::wpstrlen($pad_str);
$pad_length = $final_str_length - $str_length;
if ($pad_type == STR_PAD_RIGHT) {
$repeat = ceil($pad_length / $pad_str_length);
return UTF8::wpsubstr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
}
if ($pad_type == STR_PAD_LEFT) {
$repeat = ceil($pad_length / $pad_str_length);
return UTF8::wpsubstr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
}
if ($pad_type == STR_PAD_BOTH) {
$pad_length /= 2;
$pad_length_left = floor($pad_length);
$pad_length_right = ceil($pad_length);
$repeat_left = ceil($pad_length_left / $pad_str_length);
$repeat_right = ceil($pad_length_right / $pad_str_length);
$pad_left = UTF8::wpsubstr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
$pad_right = UTF8::wpsubstr(str_repeat($pad_str, $repeat_right), 0, $pad_length_right);
return $pad_left . $str . $pad_right;
}
}