本文整理汇总了PHP中utf8::strlen方法的典型用法代码示例。如果您正苦于以下问题:PHP utf8::strlen方法的具体用法?PHP utf8::strlen怎么用?PHP utf8::strlen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utf8
的用法示例。
在下文中一共展示了utf8::strlen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _str_pad
/**
* utf8::str_pad
*
* @package Core
* @author Kohana Team
* @copyright (c) 2007 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
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::strlen($str);
if ($final_str_length <= 0 or $final_str_length <= $str_length) {
return $str;
}
$pad_str_length = utf8::strlen($pad_str);
$pad_length = $final_str_length - $str_length;
if ($pad_type == STR_PAD_RIGHT) {
$repeat = ceil($pad_length / $pad_str_length);
return utf8::substr($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::substr(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::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
$pad_right = utf8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_left);
return $pad_left . $str . $pad_right;
}
trigger_error('utf8::str_pad: Unknown padding type (' . $type . ')', E_USER_ERROR);
}
示例2: render
/**
* Outputs the Captcha image.
*
* @param boolean $html HTML output
* @return mixed
*/
public function render($html = TRUE)
{
// Creates a black image to start from
$this->image_create(Captcha::$config['background']);
// Add random white/gray arcs, amount depends on complexity setting
$count = (Captcha::$config['width'] + Captcha::$config['height']) / 2;
$count = $count / 5 * min(10, Captcha::$config['complexity']);
for ($i = 0; $i < $count; $i++) {
imagesetthickness($this->image, mt_rand(1, 2));
$color = imagecolorallocatealpha($this->image, 255, 255, 255, mt_rand(0, 120));
imagearc($this->image, mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(0, 360), mt_rand(0, 360), $color);
}
// Use different fonts if available
$font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
// Draw the character's white shadows
$size = (int) min(Captcha::$config['height'] / 2, Captcha::$config['width'] * 0.8 / utf8::strlen($this->response));
$angle = mt_rand(-15 + utf8::strlen($this->response), 15 - utf8::strlen($this->response));
$x = mt_rand(1, Captcha::$config['width'] * 0.9 - $size * utf8::strlen($this->response));
$y = (Captcha::$config['height'] - $size) / 2 + $size;
$color = imagecolorallocate($this->image, 255, 255, 255);
imagefttext($this->image, $size, $angle, $x + 1, $y + 1, $color, $font, $this->response);
// Add more shadows for lower complexities
Captcha::$config['complexity'] < 10 and imagefttext($this->image, $size, $angle, $x - 1, $y - 1, $color, $font, $this->response);
Captcha::$config['complexity'] < 8 and imagefttext($this->image, $size, $angle, $x - 2, $y + 2, $color, $font, $this->response);
Captcha::$config['complexity'] < 6 and imagefttext($this->image, $size, $angle, $x + 2, $y - 2, $color, $font, $this->response);
Captcha::$config['complexity'] < 4 and imagefttext($this->image, $size, $angle, $x + 3, $y + 3, $color, $font, $this->response);
Captcha::$config['complexity'] < 2 and imagefttext($this->image, $size, $angle, $x - 3, $y - 3, $color, $font, $this->response);
// Finally draw the foreground characters
$color = imagecolorallocate($this->image, 0, 0, 0);
imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response);
// Output
return $this->image_render($html);
}
示例3: _substr
/**
* utf8::substr
*
* @package Core
* @author Kohana Team
* @copyright (c) 2007 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _substr($str, $offset, $length = NULL)
{
if (SERVER_UTF8) {
return $length === NULL ? mb_substr($str, $offset) : mb_substr($str, $offset, $length);
}
if (utf8::is_ascii($str)) {
return $length === NULL ? substr($str, $offset) : substr($str, $offset, $length);
}
// Normalize params
$str = (string) $str;
$strlen = utf8::strlen($str);
$offset = (int) ($offset < 0) ? max(0, $strlen + $offset) : $offset;
// Normalize to positive offset
$length = $length === NULL ? NULL : (int) $length;
// Impossible
if ($length === 0 or $offset >= $strlen or $length < 0 and $length <= $offset - $strlen) {
return '';
}
// Whole string
if ($offset == 0 and ($length === NULL or $length >= $strlen)) {
return $str;
}
// Build regex
$regex = '^';
// Create an offset expression
if ($offset > 0) {
// PCRE repeating quantifiers must be less than 65536, so repeat when necessary
$x = (int) ($offset / 65535);
$y = (int) ($offset % 65535);
$regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}';
$regex .= $y == 0 ? '' : '.{' . $y . '}';
}
// Create a length expression
if ($length === NULL) {
$regex .= '(.*)';
// No length set, grab it all
} elseif ($length > 0) {
// Reduce length so that it can't go beyond the end of the string
$length = min($strlen - $offset, $length);
$x = (int) ($length / 65535);
$y = (int) ($length % 65535);
$regex .= '(';
$regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}';
$regex .= '.{' . $y . '})';
} else {
$x = (int) (-$length / 65535);
$y = (int) (-$length % 65535);
$regex .= '(.*)';
$regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}';
$regex .= '.{' . $y . '}';
}
preg_match('/' . $regex . '/us', $str, $matches);
return $matches[1];
}
示例4: _substr_replace
/**
* utf8::substr_replace
*
* @package Core
* @author Kohana Team
* @copyright (c) 2007 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _substr_replace($str, $replacement, $offset, $length = NULL)
{
if (utf8::is_ascii($str)) {
return $length === NULL ? substr_replace($str, $replacement, $offset) : substr_replace($str, $replacement, $offset, $length);
}
$length = $length === NULL ? utf8::strlen($str) : (int) $length;
preg_match_all('/./us', $str, $str_array);
preg_match_all('/./us', $replacement, $replacement_array);
array_splice($str_array[0], $offset, $length, $replacement_array[0]);
return implode('', $str_array[0]);
}
示例5: number_to_text
public static function number_to_text($value, $separator = ' ')
{
$digits = (string) $value;
if (utf8::strpos($digits, '.') !== FALSE) {
$digits = explode('.', $digits);
return static::number_to_text($digits[0]) . $separator . static::number_to_text($digits[1]);
}
$jednosci = array('zero', 'jeden', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć', 'siedem', 'osiem', 'dziewięć');
$dziesiatki = array('', 'dziesięć', 'dwadzieścia', 'trzydzieści', 'czterdzieści', 'piećdziesiąt', 'sześćdziesiąt', 'siedemdziesiąt', 'osiemdziesiąt', 'dziewiećdziesiąt');
$setki = array('', 'sto', 'dwieście', 'trzysta', 'czterysta', 'piećset', 'sześćset', 'siedemset', 'osiemset', 'dziewiećset');
$nastki = array('dziesieć', 'jedenaście', 'dwanaście', 'trzynaście', 'czternaście', 'piętnaście', 'szesnaście', 'siedemnaście', 'osiemnaście', 'dzięwietnaście');
$tysiace = array('tysiąc', 'tysiące', 'tysięcy');
$digits = (string) $value;
$digits = utf8::strrev($digits);
$i = utf8::strlen($digits);
$string = '';
if ($i > 5 && $digits[5] > 0) {
$string .= $setki[$digits[5]] . ' ';
}
if ($i > 4 && $digits[4] > 1) {
$string .= $dziesiatki[$digits[4]] . ' ';
} elseif ($i > 3 && $digits[4] == 1) {
$string .= $nastki[$digits[3]] . ' ';
}
if ($i > 3 && $digits[3] > 0 && $digits[4] != 1) {
$string .= $jednosci[$digits[3]] . ' ';
}
$tmpStr = utf8::substr(utf8::strrev($digits), 0, -3);
if (utf8::strlen($tmpStr) > 0) {
$tmpInt = (int) $tmpStr;
if ($tmpInt == 1) {
$string .= $tysiace[0] . ' ';
} elseif ($tmpInt % 10 > 1 && $tmpInt % 10 < 5 && ($tmpInt < 10 || $tmpInt > 20)) {
$string .= $tysiace[1] . ' ';
} else {
$string .= $tysiace[2] . ' ';
}
}
if ($i > 2 && $digits[2] > 0) {
$string .= $setki[$digits[2]] . ' ';
}
if ($i > 1 && $digits[1] > 1) {
$string .= $dziesiatki[$digits[1]] . ' ';
} elseif ($i > 0 && $digits[1] == 1) {
$string .= $nastki[$digits[0]] . ' ';
}
if ($digits[0] > 0 && $digits[1] != 1) {
$string .= $jednosci[$digits[0]] . ' ';
}
return $string;
}
示例6: _strrpos
/**
* utf8::strrpos
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _strrpos($str, $search, $offset = 0)
{
$offset = (int) $offset;
if (utf8::is_ascii($str) and utf8::is_ascii($search)) {
return strrpos($str, $search, $offset);
}
if ($offset == 0) {
$array = explode($search, $str, -1);
return isset($array[0]) ? utf8::strlen(implode($search, $array)) : FALSE;
}
$str = utf8::substr($str, $offset);
$pos = utf8::strrpos($str, $search);
return $pos === FALSE ? FALSE : $pos + $offset;
}
示例7: _str_split
/**
* utf8::str_split
*
* @package Core
* @author Kohana Team
* @copyright (c) 2007 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _str_split($str, $split_length = 1)
{
$split_length = (int) $split_length;
if (utf8::is_ascii($str)) {
return str_split($str, $split_length);
}
if ($split_length < 1) {
return FALSE;
}
if (utf8::strlen($str) <= $split_length) {
return array($str);
}
preg_match_all('/.{' . $split_length . '}|[^\\x00]{1,' . $split_length . '}$/us', $str, $matches);
return $matches[0];
}
示例8: generate_challenge
/**
* Generates a new Captcha challenge.
*
* @return string The challenge answer
*/
public function generate_challenge()
{
// Load words from the current language and randomize them
$words = Kohana::config('captcha.words');
shuffle($words);
// Loop over each word...
foreach ($words as $word) {
// ...until we find one of the desired length
if (abs(Captcha::$config['complexity'] - utf8::strlen($word)) < 2) {
return utf8::strtoupper($word);
}
}
// Return any random word as final fallback
return utf8::strtoupper($words[array_rand($words)]);
}
示例9: _strcspn
/**
* utf8::strcspn
*
* @package Core
* @author Kohana Team
* @copyright (c) 2007 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _strcspn($str, $mask, $offset = NULL, $length = NULL)
{
if ($str == '' or $mask == '') {
return 0;
}
if (utf8::is_ascii($str) and utf8::is_ascii($mask)) {
return $offset === NULL ? strcspn($str, $mask) : ($length === NULL ? strcspn($str, $mask, $offset) : strcspn($str, $mask, $offset, $length));
}
if ($start !== NULL or $length !== NULL) {
$str = utf8::substr($str, $offset, $length);
}
// Escape these characters: - [ ] . : \ ^ /
// The . and : are escaped to prevent possible warnings about POSIX regex elements
$mask = preg_replace('#[-[\\].:\\\\^/]#', '\\\\$0', $mask);
preg_match('/^[^' . $mask . ']+/u', $str, $matches);
return isset($matches[0]) ? utf8::strlen($matches[0]) : 0;
}
示例10: length
/**
* Rule: length. Generates an error if the field is too long or too short.
*
* @param mixed input value
* @param array minimum, maximum, or exact length to match
* @return bool
*/
public function length($str, array $length)
{
if (!is_string($str)) {
return FALSE;
}
$str = strip_tags($str);
$size = utf8::strlen($str);
$status = FALSE;
if (count($length) > 1) {
list($min, $max) = $length;
if ($size >= $min and $size <= $max) {
$status = TRUE;
}
} else {
$status = $size === (int) $length[0];
}
return $status;
}
示例11: upload
public function upload()
{
if (!$_FILES) {
return;
}
$surfix = Kohana::config('torn')->surfix->temp;
$surfix_len = utf8::strlen($surfix);
foreach ($_POST as $key => $tmp_name) {
if (utf8::substr($key, -$surfix_len) == $surfix) {
$field = utf8::substr($key, 0, -$surfix_len);
$this->parent->model->set($field, $tmp_name);
}
}
$cache = Cache::instance();
foreach ($_FILES as $key => $upload) {
$this->parent->model->set($key, $upload);
if (!isset($this->parent->fields[$key]) or !$this->parent->fields[$key] instanceof Torn_Field_File) {
continue;
}
if (upload::not_empty($upload) and upload::valid($upload)) {
$seed = Arr::get($_POST, '__SEED__', md5(Request::current()->uri() . time()));
$tmp_name = $seed . '-' . md5_file($upload['tmp_name']);
if (upload::save($upload, $tmp_name, Kohana::$cache_dir) !== FALSE) {
$timestamp = 24 * 60 * 60;
$cache->set($tmp_name, array('upload' => $upload, 'timestamp' => $timestamp), $timestamp);
$tmp_old_file = Arr::get($_POST, $key . $surfix);
if (!empty($tmp_old_file) and file_exists(Kohana::$cache_dir . DIRECTORY_SEPARATOR . $tmp_old_file)) {
try {
unlink(Kohana::$cache_dir . DIRECTORY_SEPARATOR . $tmp_old_file);
$cache->delete($tmp_old_file);
} catch (Exception $e) {
}
}
$this->parent->model->set($key, $tmp_name);
}
}
}
}
示例12: account_number
public function account_number($p_iNRB)
{
// Usuniecie spacji
$iNRB = utf8::str_ireplace(' ', '', $p_iNRB);
// Sprawdzenie czy przekazany numer zawiera 26 znaków
if (utf8::strlen($iNRB) != 26) {
die('fail #1');
return false;
}
// Zdefiniowanie tablicy z wagami poszczególnych cyfr
$aWagiCyfr = array(1, 10, 3, 30, 9, 90, 27, 76, 81, 34, 49, 5, 50, 15, 53, 45, 62, 38, 89, 17, 73, 51, 25, 56, 75, 71, 31, 19, 93, 57);
// Dodanie kodu kraju (w tym przypadku dodajemy kod PL)
$iNRB = $iNRB . '2521';
$iNRB = utf8::substr($iNRB, 2) . utf8::substr($iNRB, 0, 2);
// Wyzerowanie zmiennej
$iSumaCyfr = 0;
// Pćtla obliczająca sumć cyfr w numerze konta
for ($i = 0; $i < 30; $i++) {
$iSumaCyfr += $iNRB[29 - $i] * $aWagiCyfr[$i];
}
// Sprawdzenie czy modulo z sumy wag poszczegolnych cyfr jest rowne 1
return $iSumaCyfr % 97 == 1;
}
示例13: render
/**
* Outputs the Captcha image.
*
* @param boolean $html HTML output
* @return mixed
*/
public function render($html = TRUE)
{
// Creates $this->image
$this->image_create(Captcha::$config['background']);
// Add a random gradient
if (empty(Captcha::$config['background'])) {
$color1 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
$color2 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
$this->image_gradient($color1, $color2);
}
// Add a few random lines
for ($i = 0, $count = mt_rand(5, Captcha::$config['complexity'] * 4); $i < $count; $i++) {
$color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(100, 255), mt_rand(50, 120));
imageline($this->image, mt_rand(0, Captcha::$config['width']), 0, mt_rand(0, Captcha::$config['width']), Captcha::$config['height'], $color);
}
// Calculate character font-size and spacing
$default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / (utf8::strlen($this->response) + 1);
$spacing = (int) (Captcha::$config['width'] * 0.9 / utf8::strlen($this->response));
// Draw each Captcha character with varying attributes
for ($i = 0, $strlen = utf8::strlen($this->response); $i < $strlen; $i++) {
// Use different fonts if available
$font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
// Allocate random color, size and rotation attributes to text
$color = imagecolorallocate($this->image, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150));
$angle = mt_rand(-40, 20);
// Scale the character size on image height
$size = $default_size / 10 * mt_rand(8, 12);
$box = imageftbbox($size, $angle, $font, utf8::substr($this->response, $i, 1));
// Calculate character starting coordinates
$x = $spacing / 4 + $i * $spacing;
$y = Captcha::$config['height'] / 2 + ($box[2] - $box[5]) / 4;
// Write text character to image
imagefttext($this->image, $size, $angle, $x, $y, $color, $font, utf8::substr($this->response, $i, 1));
}
// Output
return $this->image_render($html);
}
示例14: shorten_string
public static function shorten_string($str, $max_length, $mid_cut = false)
{
if (!is_scalar($str)) {
return false;
}
if (!is_int($max_length)) {
return false;
}
$length = utf8::strlen($str);
if ($length <= $max_length) {
return $str;
} elseif ($mid_cut) {
$mid = (int) ceil($max_length / 2);
$string = utf8::substr($str, 0, $mid) . '...' . utf8::substr($str, $mid);
} else {
return utf8::substr($str, 0, $max_length) . '...';
}
}
示例15: aggiungiutente
function aggiungiutente()
{
global $SITENAME, $SITEEMAIL, $db, $BASEURL, $VALIDATION, $USERLANG, $USE_IMAGECODE;
$utente = $db->real_escape_string($_POST["user"]);
$pwd = $db->real_escape_string($_POST["pwd"]);
$pwd1 = $db->real_escape_string($_POST["pwd1"]);
$email = $db->real_escape_string($_POST["email"]);
$idlangue = intval($_POST["language"]);
$idstyle = intval($_POST["style"]);
$idflag = intval($_POST["flag"]);
$timezone = intval($_POST["timezone"]);
if (utf8::strtoupper($utente) == utf8::strtoupper("Guest")) {
print ERROR . " " . ERR_GUEST_EXISTS . "<br />\n";
print "<a href='account.php'>" . BACK . "</a>";
block_end();
stdfoot();
exit;
}
if ($pwd != $pwd1) {
print ERROR . " " . DIF_PASSWORDS . "<br />\n";
print "<a href='account.php'>" . BACK . "</a>";
block_end();
stdfoot();
exit;
}
if ($VALIDATION == "none") {
$idlevel = 3;
} else {
$idlevel = 2;
}
# Create Random number
$floor = 100000;
$ceiling = 999999;
srand((double) microtime() * 1000000);
$random = mt_rand($floor, $ceiling);
if ($utente == "" || $pwd == "" || $email == "") {
return -1;
exit;
}
$res = $db->query("SELECT email FROM users WHERE email = '" . $email . "'");
if ($res->num_rows > 0) {
return -2;
exit;
}
if (!security::valid_email($email)) {
return -3;
exit;
}
// duplicate username
$res = $db->query("SELECT username FROM users WHERE username = '" . $utente . "'");
if ($res->num_rows > 0) {
return -4;
exit;
}
// duplicate username
if (strpos($db->real_escape_string($utente), " ") == true) {
return -7;
exit;
}
if ($USE_IMAGECODE) {
if (extension_loaded('gd')) {
$arr = gd_info();
if ($arr['FreeType Support'] == 1) {
$public = $_POST['public_key'];
$private = $_POST['private_key'];
$p = new ocr_captcha();
if ($p->check_captcha($public, $private) != true) {
err_msg(ERROR, ERR_IMAGE_CODE);
block_end();
stdfoot();
exit;
}
}
}
}
$bannedchar = array("\\", "/", ":", "*", "?", "\"", "@", "\$", "'", "`", ",", ";", ".", "<", ">", "!", "£", "%", "^", "&", "(", ")", "+", "=", "#", "~");
if (straipos($db->real_escape_string($utente), $bannedchar) == true) {
return -8;
exit;
}
if (utf8::strlen($db->real_escape_string($pwd)) < 4) {
return -9;
exit;
}
@$db->query("INSERT INTO users (username, password, random, id_level, email, style, language, flag, joined, lastconnect, pid, time_offset) VALUES ('" . $utente . "', '" . md5($pwd) . "', " . $random . ", " . $idlevel . ", '" . $email . "', " . $idstyle . ", " . $idlangue . ", " . $idflag . ", NOW(), NOW(), '" . md5(uniqid(mt_rand(), true)) . "', '" . $timezone . "')");
if ($VALIDATION == "user") {
ini_set("sendmail_from", "");
if ($db->errno == 0) {
mail($email, ACCOUNT_CONFIRM, ACCOUNT_MSG . "\n\n" . $BASEURL . "/account.php?act=confirm&confirm=" . $random . "&language=" . $idlangue . "", "From: " . $SITENAME . " <" . $SITEEMAIL . ">");
write_log("Signup new User " . $utente . " (" . $email . ")", "add");
} else {
die($db->error);
}
}
return $db->errno;
}