/** * Smarty truncate modifier plugin * * Type: modifier<br> * Name: truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string or inserting $etc into the middle. * * @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @param string $string input string * @param integer $length length of truncated text * @param string $etc end string * @param boolean $break_words truncate at word boundary * @param boolean $middle truncate in the middle of text * @return string truncated string */ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { if ($length == 0) { return ''; } if (SMARTY_MBSTRING && empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])) { if (mb_strlen($string, SMARTY_RESOURCE_CHAR_SET) > $length) { $length -= min($length, mb_strlen($etc, SMARTY_RESOURCE_CHAR_SET)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/u', '', mb_substr($string, 0, $length + 1, SMARTY_RESOURCE_CHAR_SET)); } if (!$middle) { return mb_substr($string, 0, $length, SMARTY_RESOURCE_CHAR_SET) . $etc; } return mb_substr($string, 0, $length / 2, SMARTY_RESOURCE_CHAR_SET) . $etc . mb_substr($string, -$length / 2, $length, SMARTY_RESOURCE_CHAR_SET); } return $string; } // no MBString fallback if (isset($string[$length])) { $length -= min($length, strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1)); } if (!$middle) { return substr($string, 0, $length) . $etc; } return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2); } return $string; }
/** * 替换屏蔽字 */ public function replace() { $content = trim(urldecode($this->input['banword'])); $symbol = trim(urldecode($this->input['symbol'])); if (empty($content)) { $this->errorOutput(OBJECT_NULL); } $data = $this->banword($content); if ($data) { $replace = array(); $find = array(); foreach ($data as $v) { if (!empty($symbol) && $symbol != '*') { $replace[] = $symbol; } else { if (!empty($v['banwd'])) { $replace[] = $v['banwd']; } else { $replace[] = str_repeat('*', mb_strlen($v['banname'], 'utf-8')); } } $find[] = $v['banname']; } $content = str_replace($find, $replace, $content); } $this->addItem($content); $this->output(); }
public function stem($word) { if (mb_strlen($word, 'utf-8') >= $this->min) { return preg_replace($this->regex, '', $word); } return $word; }
/** * Smarty truncate modifier plugin * Type: modifier<br> * Name: truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string or inserting $etc into the middle. * * @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * * @param string $string input string * @param integer $length length of truncated text * @param string $etc end string * @param boolean $break_words truncate at word boundary * @param boolean $middle truncate in the middle of text * * @return string truncated string */ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { if ($length == 0) { return ''; } if (Smarty::$_MBSTRING) { if (mb_strlen($string, Smarty::$_CHARSET) > $length) { $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)); } if (!$middle) { return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc; } return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET); } return $string; } // no MBString fallback if (isset($string[$length])) { $length -= min($length, strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1)); } if (!$middle) { return substr($string, 0, $length) . $etc; } return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2); } return $string; }
private function assertSerializedMessageSize($expectedContent, $message) { $context = $this->config->createComputeSizeContext(); $expectedSize = mb_strlen($expectedContent, '8bit'); $actualSize = $message->serializedSize($context); $this->assertEquals($expectedSize, $actualSize); }
function subtex1t4Question1($text, $length) { if (mb_strlen($text, 'utf8') > $length) { return mb_substr($text, 0, $length, 'utf8') . '...'; } return $text; }
function VerifySupplierDescription($supplierdescription, $i, $Errors) { if (mb_strlen($supplierdescription) > 50) { $Errors[$i] = InvalidSupplierDescription; } return $Errors; }
/** * Visit the given URI with a JSON request. * * @param string $method * @param string $uri * @param array $data * @param array $headers * @return $this */ public function json($method, $uri, array $data = [], array $headers = []) { $content = json_encode($data); $headers = array_merge(['CONTENT_LENGTH' => mb_strlen($content, '8bit'), 'CONTENT_TYPE' => 'application/json', 'Accept' => 'application/json'], $headers); $this->call($method, $uri, [], [], [], $this->transformHeadersToServerVars($headers), $content); return $this; }
function str_pad_unicode($str, $pad_len, $pad_str = ' ', $dir = STR_PAD_RIGHT) { $str_len = mb_strlen($str); $pad_str_len = mb_strlen($pad_str); if (!$str_len && ($dir == STR_PAD_RIGHT || $dir == STR_PAD_LEFT)) { $str_len = 1; // @debug } if (!$pad_len || !$pad_str_len || $pad_len <= $str_len) { return $str; } $result = null; $repeat = ceil($str_len - $pad_str_len + $pad_len); if ($dir == STR_PAD_RIGHT) { $result = $str . str_repeat($pad_str, $repeat); $result = mb_substr($result, 0, $pad_len); } else { if ($dir == STR_PAD_LEFT) { $result = str_repeat($pad_str, $repeat) . $str; $result = mb_substr($result, -$pad_len); } else { if ($dir == STR_PAD_BOTH) { $length = ($pad_len - $str_len) / 2; $repeat = ceil($length / $pad_str_len); $result = mb_substr(str_repeat($pad_str, $repeat), 0, floor($length)) . $str . mb_substr(str_repeat($pad_str, $repeat), 0, ceil($length)); } } } return $result; }
function mmstrlen($str) { $standalones = array("ဤ", "၍", "ဪ", "၏", "၊", "။", "၌"); $consonants = array("က", "ခ", "ဂ", "ဃ", "င", "စ", "ဆ", "ဇ", "ဈ", "ည", "ဍ", "ဌ", "ဋ", "ဎ", "ဏ", "တ", "ထ", "ဒ", "ဓ", "န", "ပ", "ဖ", "ဗ", "ဘ", "မ", "ယ", "ရ", "လ", "ဝ", "သ", "ဟ", "ဠ", "အ"); $numbers = array("၀", "၁", "၂", "၃", "၄", "၅", "၆", "၇", "၈", "၉"); $len = mb_strlen($str, "UTF-8"); $count = 0; for ($i = 0; $i < $len; $i++) { $char = mb_substr($str, $i, 1, "UTF-8"); if (!burmese($char)) { $count++; } else { if (in_array($char, $consonants) || in_array($char, $standalones) || in_array($char, $numbers) || $char == " ") { $count++; } if ($char == "်") { $prev = mb_substr($str, $i - 1, 1, "UTF-8"); if (in_array($prev, $consonants)) { $count--; } } } } return $count; }
function _strlen($string) { if ($this->is_overloaded) { return mb_strlen($string,'ascii'); } else { return strlen($string); } }
/** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (!$constraint instanceof Length) { throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\Length'); } if (null === $value || '' === $value) { return; } if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } $stringValue = (string) $value; if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) { $length = grapheme_strlen($stringValue); } elseif (function_exists('mb_strlen')) { $length = mb_strlen($stringValue, $constraint->charset); } else { $length = strlen($stringValue); } if (null !== $constraint->max && $length > $constraint->max) { $this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->max)->setInvalidValue($value)->setPlural((int) $constraint->max)->setCode(Length::TOO_LONG_ERROR)->addViolation(); return; } if (null !== $constraint->min && $length < $constraint->min) { $this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->min)->setInvalidValue($value)->setPlural((int) $constraint->min)->setCode(Length::TOO_SHORT_ERROR)->addViolation(); } }
/** * Stores new key in DB * * @param string $type Type: necessary * @param string|null $key Key: optional key, otherwise a key will be generated * @param mixed|null $uid Uid: optional (if used, only this user can use this key) * @param string|array|null $content Content: up to 255 characters of content may be added (optional) * NOW: checks if this key is already used (should be unique in table) * @return string key on SUCCESS, boolean false otherwise */ public function newKey($type, $key = null, $uid = null, $content = null) { if (empty($type)) { return false; } if (empty($key)) { $key = $this->generateKey($this->defaultLength); $keyLength = $this->defaultLength; } else { $keyLength = mb_strlen($key); } if (is_array($content)) { $content = json_encode($content); } $data = ['type' => $type, 'user_id' => $uid, 'content' => (string) $content, 'key' => $key]; $entity = $this->newEntity($data); $max = 99; while (!$this->save($entity)) { $entity['key'] = $this->generateKey($keyLength); $max--; if ($max === 0) { return false; } } return $entity['key']; }
private function showError($text) { $text = mb_substr($text, 20, mb_strlen($text, 'utf8'), 'utf8'); $text = explode('Stack trace:', $text); $text = $text[0]; return $text; }
public function getKeywords($generateIfEmpty = true, $data = null) { $keywords = parent::getKeywords(); if (!$generateIfEmpty) { return $keywords; } if ($keywords == null && $data != null) { $preg = '/<h[123456].*?>(.*?)<\\/h[123456]>/i'; $content = str_replace("\n", "", str_replace("\r", "", $data)); $pregCount = preg_match_all($preg, $content, $headers); $keywords = ''; for ($i = 0; $i < $pregCount; $i++) { if ($keywords != '') { $keywords .= ', '; } $item = trim(strip_tags($headers[0][$i])); if ($item == '') { continue; } $keywords .= $item; if (mb_strlen($keywords) > 200) { break; } } } if ($keywords == null && isset(Yii::app()->domain)) { $keywords = Yii::app()->domain->model->keywords; } return str_replace('@', '[at]', $keywords); }
/** * Get the size of a cache entry * * @param string $id cache id * * @return int size in bytes */ public function getSize($id) { if (!$this->_fetch($id)) { return false; } return function_exists('mb_strlen') && (int) ini_get('mbstring.func_overload') & 2 ? mb_strlen($this->_data, '8bit') : strlen($this->_data); }
/** * Smarty mb_truncate modifier plugin * * Type: modifier<br> * Name: mb_truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string. (MultiByte version) * @link http://smarty.php.net/manual/en/language.modifier.truncate.php * truncate (Smarty online manual) * @param string * @param string * @param integer * @param string * @param boolean * @return string */ function smarty_modifier_mb_truncate($string, $length = 80, $etc = '...', $break_words = false) { if ($length == 0) { return ''; } $string = str_replace("&", "&", $string); if (function_exists("mb_internal_encoding") && function_exists("mb_strlen") && function_exists("mb_substr")) { mb_internal_encoding("UTF8"); if (mb_strlen($string) > $length) { $length -= mb_strlen($etc); if (!$break_words) { $string = preg_replace('/\\s+?(\\S+)?$/', '', mb_substr($string, 0, $length + 1)); } $string = mb_substr($string, 0, $length) . $etc; } } else { //modifier.truncate if (strlen($string) > $length) { $length -= strlen($etc); if (!$break_words) { $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1)); } $string = substr($string, 0, $length) . $etc; } } $string = str_replace("&", "&", $string); return $string; }
/** * Generate a valid Google Translate request token. * * @param string $a text to translate * * @return string */ private function TL($a) { $b = $this->generateB(); for ($d = [], $e = 0, $f = 0; $f < mb_strlen($a, 'UTF-8'); $f++) { $g = $this->charCodeAt($a, $f); if (128 > $g) { $d[$e++] = $g; } else { if (2048 > $g) { $d[$e++] = $g >> 6 | 192; } else { if (55296 == ($g & 64512) && $f + 1 < mb_strlen($a, 'UTF-8') && 56320 == ($this->charCodeAt($a, $f + 1) & 64512)) { $g = 65536 + (($g & 1023) << 10) + ($this->charCodeAt($a, ++$f) & 1023); $d[$e++] = $g >> 18 | 240; $d[$e++] = $g >> 12 & 63 | 128; } else { $d[$e++] = $g >> 12 | 224; $d[$e++] = $g >> 6 & 63 | 128; } } $d[$e++] = $g & 63 | 128; } } $a = $b; for ($e = 0; $e < count($d); $e++) { $a += $d[$e]; $a = $this->RL($a, '+-a^+6'); } $a = $this->RL($a, '+-3^+b+-f'); if (0 > $a) { $a = ($a & 2147483647) + 2147483648; } $a = fmod($a, pow(10, 6)); return $a . '.' . ($a ^ $b); }
/** * Smarty truncate modifier plugin * * Type: modifier<br> * Name: truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string or inserting $etc into the middle. * * @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @param string $string input string * @param integer $length lenght of truncated text * @param string $etc end string * @param boolean $break_words truncate at word boundary * @param boolean $middle truncate in the middle of text * @return string truncated string */ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { if ($length == 0) { return ''; } if (is_callable('mb_strlen')) { if (mb_strlen($string) > $length) { $length -= min($length, mb_strlen($etc)); if (!$break_words && !$middle) { $string = mb_ereg_replace('/\\s+?(\\S+)?$/', '', mb_substr($string, 0, $length + 1), 'p'); } if (!$middle) { return mb_substr($string, 0, $length) . $etc; } else { return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, -$length / 2); } } else { return $string; } } else { if (strlen($string) > $length) { $length -= min($length, strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1)); } if (!$middle) { return substr($string, 0, $length) . $etc; } else { return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2); } } else { return $string; } } }
function isValid($username, $password) { if (mb_strlen($username, "UTF-8") > 3 && mb_strlen($password, "UTF-8") > 3) { return true; } return false; }
/** * Smarty count_characters modifier plugin * * Type: modifier<br> * Name: count_characteres<br> * Purpose: count the number of characters in a text * @link http://smarty.php.net/manual/en/language.modifier.count.characters.php * count_characters (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @param string * @param boolean include whitespace in the character count * @return integer */ function smarty_modifier_count_characters($string, $include_spaces = false) { if ($include_spaces) { return mb_strlen($string); } return preg_match_all("/[^\\s]/", $string, $match); }
/** * Calculates password strength score * * @author David Hübner <david.hubner at google.com> * @param string $value - password * @return int (1 = very weak, 2 = weak, 3 = medium, 4+ = strong) */ private function countScore($value) { $score = 0; $hasLower = preg_match('![a-z]!', $value); $hasUpper = preg_match('![A-Z]!', $value); $hasNumber = preg_match('![0-9]!', $value); if ($hasLower && $hasUpper) { ++$score; } if ($hasNumber && $hasLower || $hasNumber && $hasUpper) { ++$score; } if (preg_match('![^0-9a-zA-Z]!', $value)) { ++$score; } $length = mb_strlen($value); if ($length >= 16) { $score += 2; } elseif ($length >= 8) { ++$score; } elseif ($length <= 4 && $score > 1) { --$score; } elseif ($length > 0 && $score === 0) { ++$score; } return $score; }
private function _splitToTokens() { $content = $this->_doc_content; $tmp = array(); $tmp2 = array(); $slength = array(); $content = str_replace(".", " ", $content); $tmp = explode(" ", $content); foreach ($tmp as $word) { // let's count only words with more then 4 chars if (mb_strlen($word, $this->_charset) > 3) { $tmp2[$word] = $word; $slength[$word] = strlen($word); } } array_multisort($slength, SORT_DESC, $tmp2, SORT_ASC); $count = count($slength); // Save only top15 (by length) sentences/words for ($i = 0; $i < $count && $i < 15; $i++) { $this->_tokens[] = current($tmp2); next($tmp2); } $this->length = count($this->_tokens); return $this; }
/** * Set the name * * @param $name * @throw \Pangaea\PangaeaException */ public function setName($name) { if (mb_strlen($name) === 0) { throw new PangaeaException('VariantMetaData NameValueAttribute element "name" cannot be blank'); } $this->name = $name; }
/** * @brief Parse une réponse ftp * @param $rawResponse string la chaîne d'instruction ftp * @return FTPMessage */ public static function &parse($rawResponse) { $rv = null; $matches = array(); preg_match('~([0-9]{3} )?(.*)$~', trim($rawResponse), $matches); if (0 != count($matches)) { $responseCode = isset($matches[1]) && mb_strlen($matches[1]) > 0 ? trim($matches[1]) : null; $commandName = null; $commandParams = null; if (strlen($matches[2]) > 0) { if (is_null($responseCode)) { // Pas de code donc surement une commande preg_match('~([A-Z]+)( .*)?$~', trim($matches[2]), $matches); if (count($matches) > 0) { $commandName = trim($matches[1]); $commandParams = isset($matches[2]) ? trim($matches[2]) : null; } } else { $commandParams = trim($matches[2]); } } $rv =& new FTPMessage($rawResponse, $responseCode, $commandName, $commandParams); } return $rv; }
private static function toTitleCase($str) { if (mb_strlen($str) === 0) { return $str; } return mb_strtoupper(mb_substr($str, 0, 1)) . mb_strtolower(mb_substr($str, 1)); }
public static function clean_token($token) { if (mb_strlen($token, "UTF-8") > self::MAX_PAYLOAD_SIZE) { throw new Exception("Token exceeds maximum length allowed"); } return $token; }
public static function process($prefix, $key) { $languageService = BOL_LanguageService::getInstance(); $list = $languageService->findActiveList(); $currentLanguageId = OW::getLanguage()->getCurrentId(); $currentLangValue = ""; foreach ($list as $item) { $keyDto = $languageService->findKey($prefix, $key); if (empty($keyDto)) { $prefixDto = $languageService->findPrefix($prefix); $keyDto = $languageService->addKey($prefixDto->getId(), $key); } $value = trim($_POST['lang'][$item->getId()][$prefix][$key]); if (mb_strlen(trim($value)) == 0 || $value == json_decode('"\\u00a0"')) { $value = ' '; } $dto = $languageService->findValue($item->getId(), $keyDto->getId()); if ($dto !== null) { $event = new OW_Event('admin.before_save_lang_value', array('dto' => $dto)); OW::getEventManager()->trigger($event); if ($dto->getValue() !== $value) { $languageService->saveValue($dto->setValue($value)); } } else { $dto = $languageService->addValue($item->getId(), $prefix, $key, $value); } if ((int) $currentLanguageId === (int) $item->getId()) { $currentLangValue = $value; } } exit(json_encode(array('result' => 'success', 'prefix' => $prefix, 'key' => $key, 'value' => $currentLangValue))); }
function get_user_withdraw($limit, $user_id) { $user_id = intval($user_id); $list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "withdraw where user_id = " . $user_id . " and is_delete = 0 order by create_time desc limit " . $limit); foreach ($list as $k => $v) { $bank_account_end = substr($v['bank_account'], -4, 4); $bank_account_show_length = strlen($v['bank_account']) - 4; $bank_account = ""; for ($i = 0; $i < $bank_account_show_length; $i++) { $bank_account .= "*"; } $bank_account .= $bank_account_end; $list[$k]['bank_account'] = $bank_account; $bank_user_end = msubstr($v['bank_user'], -1, 1, "utf-8", false); $bank_user_show_length = mb_strlen($v['bank_user'], "utf-8") - 1; $bank_user = ""; for ($i = 0; $i < $bank_user_show_length; $i++) { $bank_user .= "*"; } $bank_user .= $bank_user_end; $list[$k]['bank_user'] = $bank_user; } $count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "withdraw where user_id = " . $user_id . " and is_delete = 0"); return array("list" => $list, 'count' => $count); }
/** * Get the number of bytes in cryptographic strings. * * @param string * @return int */ private static function safeStrlen($str) { if (function_exists('mb_strlen')) { return mb_strlen($str, '8bit'); } return strlen($str); }