本文整理汇总了PHP中mb_strlen函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_strlen函数的具体用法?PHP mb_strlen怎么用?PHP mb_strlen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mb_strlen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_modifier_truncate
/**
* 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;
}
示例2: replace
/**
* 替换屏蔽字
*/
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();
}
示例3: stem
public function stem($word)
{
if (mb_strlen($word, 'utf-8') >= $this->min) {
return preg_replace($this->regex, '', $word);
}
return $word;
}
示例4: smarty_modifier_truncate
/**
* 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;
}
示例5: assertSerializedMessageSize
private function assertSerializedMessageSize($expectedContent, $message)
{
$context = $this->config->createComputeSizeContext();
$expectedSize = mb_strlen($expectedContent, '8bit');
$actualSize = $message->serializedSize($context);
$this->assertEquals($expectedSize, $actualSize);
}
示例6: subtex1t4Question1
function subtex1t4Question1($text, $length)
{
if (mb_strlen($text, 'utf8') > $length) {
return mb_substr($text, 0, $length, 'utf8') . '...';
}
return $text;
}
示例7: VerifySupplierDescription
function VerifySupplierDescription($supplierdescription, $i, $Errors)
{
if (mb_strlen($supplierdescription) > 50) {
$Errors[$i] = InvalidSupplierDescription;
}
return $Errors;
}
示例8: json
/**
* 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;
}
示例9: str_pad_unicode
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;
}
示例10: mmstrlen
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;
}
示例11: _strlen
function _strlen($string) {
if ($this->is_overloaded) {
return mb_strlen($string,'ascii');
} else {
return strlen($string);
}
}
示例12: validate
/**
* {@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();
}
}
示例13: newKey
/**
* 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'];
}
示例14: showError
private function showError($text)
{
$text = mb_substr($text, 20, mb_strlen($text, 'utf8'), 'utf8');
$text = explode('Stack trace:', $text);
$text = $text[0];
return $text;
}
示例15: getKeywords
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);
}