当前位置: 首页>>代码示例>>PHP>>正文


PHP UTF8::substr方法代码示例

本文整理汇总了PHP中UTF8::substr方法的典型用法代码示例。如果您正苦于以下问题:PHP UTF8::substr方法的具体用法?PHP UTF8::substr怎么用?PHP UTF8::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UTF8的用法示例。


在下文中一共展示了UTF8::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _str_pad

/**
 * UTF8::str_pad
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2010 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_right);
        return $pad_left . $str . $pad_right;
    }
    trigger_error('UTF8::str_pad: Unknown padding type (' . $pad_type . ')', E_USER_ERROR);
}
开发者ID:azuya,项目名称:Wi3,代码行数:40,代码来源:str_pad.php

示例2: _str_pad

/**
 * UTF8::str_pad
 *
 * @package        Kohana
 * @author         Kohana Team
 * @copyright  (c) 2007-2012 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_right);
        return $pad_left . $str . $pad_right;
    }
    throw new UTF8_Exception("UTF8::str_pad: Unknown padding type (:pad_type)", [':pad_type' => $pad_type]);
}
开发者ID:s4urp8n,项目名称:kohana-admin,代码行数:40,代码来源:str_pad.php

示例3: action_ent

 public function action_ent()
 {
     $answers = Security::xss_clean(Arr::get($_POST, 'answers', ''));
     $answers = UTF8::substr($answers, 0, UTF8::strlen($answers) - 1);
     $list = explode(',', $answers);
     $total = 0;
     $right = 0;
     $points = array();
     foreach ($list as $item) {
         $total++;
         $e = explode('.', $item);
         $quest = ORM::factory('Ent_Quest', (int) $e[0]);
         if ($quest->loaded()) {
             $variant = ORM::factory('Quest_Variant')->where('quest_id', '=', $quest->id)->and_where('id', '=', (int) $e[1])->and_where('right', '=', '1')->find();
             if ($variant->loaded()) {
                 $right++;
                 $points[] = array('quest' => $quest->id, 'right' => 1);
             } else {
                 $points[] = array('quest' => $quest->id, 'right' => 0);
             }
         }
     }
     $data = array('total' => $total, 'right' => $right, 'points' => $points);
     $this->response->body(json_encode($data));
 }
开发者ID:HappyKennyD,项目名称:teest,代码行数:25,代码来源:Ajax.php

示例4: snippet

 public function snippet($text = '')
 {
     $description = '';
     $chars = array('.', '!', '?', ':', '"');
     if (!empty($text)) {
         $text = strip_tags($text);
         $arr = explode(' ', $text);
         foreach ($arr as $k => $v) {
             if (!empty($v)) {
                 $countdescription = UTF8::strlen($description);
                 $countword = UTF8::strlen($v);
                 if ($countdescription - 1 + $countword > 140) {
                     break;
                 } else {
                     $description .= $v . ' ';
                 }
             }
         }
         $description = rtrim($description);
         if (!empty($description)) {
             $lastchar = $description[UTF8::strlen($description) - 1];
             if ($lastchar == ',') {
                 $description = UTF8::substr($description, 0, UTF8::strlen($description) - 1);
             }
             if (!in_array($lastchar, $chars)) {
                 $description .= '...';
             }
         }
     }
     $this->description = $description;
     return $this;
 }
开发者ID:HappyKennyD,项目名称:teest,代码行数:32,代码来源:Metadata.php

示例5: smarty_modifier_shorter

/**
 * Smarty string_format modifier plugin
 *
 * Type:     modifier<br>
 * Name:     shorter<br>
 * Purpose:  shorter strings to lenght
 * @link http://smarty.php.net/manual/en/language.modifier.string.format.php
 *          string_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @return string
 */
function smarty_modifier_shorter($string, $lenght = 30)
{
    return UTF8::substr($string, 0, $lenght);
    if (strlen($string) > $lenght) {
        return ParseHTMLText::shortenText($string, $lenght);
    }
    return $string;
}
开发者ID:Tomeno,项目名称:lulcobang,代码行数:21,代码来源:modifier.shorter.php

示例6: _wordwrap

/**
 * UTF8::wordwrap
 * Taken and adapted form Zend Framework by Ivan Tcholakov, 2015.
 *
 * @param       string          The input string.
 * @param       int             The number of characters at which the string will be wrapped.
 * @param       string          The line is broken using the optional break parameter.
 * @param       bool            If the cut is set to TRUE, the string is always wrapped at or before the specified width.
 * @return      string|false
 * @license     @license        http://framework.zend.com/license/new-bsd New BSD License
 */
function _wordwrap($string, $width = 75, $break = "\n", $cut = false)
{
    $string = @(string) $string;
    if ($string === '') {
        return '';
    }
    $break = @(string) $break;
    if ($break === '') {
        trigger_error('UTF8::wordwrap(): Break string cannot be empty.', E_USER_WARNING);
        return false;
    }
    $width = (int) $width;
    if ($width === 0 && $cut) {
        trigger_error('UTF8::wordwrap(): Cannot force cut when width is zero.', E_USER_WARNING);
        return false;
    }
    $string_length = UTF8::strlen($string);
    $break_length = UTF8::strlen($break);
    $result = '';
    $last_start = 0;
    $last_space = 0;
    for ($current = 0; $current < $string_length; $current++) {
        $char = UTF8::substr($string, $current, 1);
        $possible_break = $char;
        if ($break_length !== 1) {
            $possible_break = UTF8::substr($string, $current, $break_length);
        }
        if ($possible_break === $break) {
            $result .= UTF8::substr($string, $last_start, $current - $last_start + $break_length);
            $current += $break_length - 1;
            $last_start = $last_space = $current + 1;
            continue;
        }
        if ($char === ' ') {
            if ($current - $last_start >= $width) {
                $result .= UTF8::substr($string, $last_start, $current - $last_start) . $break;
                $last_start = $current + 1;
            }
            $last_space = $current;
            continue;
        }
        if ($current - $last_start >= $width && $cut && $last_start >= $last_space) {
            $result .= UTF8::substr($string, $last_start, $current - $last_start) . $break;
            $last_start = $last_space = $current;
            continue;
        }
        if ($current - $last_start >= $width && $last_start < $last_space) {
            $result .= UTF8::substr($string, $last_start, $last_space - $last_start) . $break;
            $last_start = $last_space = $last_space + 1;
            continue;
        }
    }
    if ($last_start !== $current) {
        $result .= UTF8::substr($string, $last_start, $current - $last_start);
    }
    return $result;
}
开发者ID:Qnatz,项目名称:starter-public-edition-4,代码行数:68,代码来源:wordwrap.php

示例7: _strpos

/**
 * UTF8::strpos
 *
 * @package        Kohana
 * @author         Kohana Team
 * @copyright  (c) 2007-2012 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license        http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strpos($str, $search, $offset = 0)
{
    $offset = (int) $offset;
    if (UTF8::is_ascii($str) and UTF8::is_ascii($search)) {
        return strpos($str, $search, $offset);
    }
    if ($offset == 0) {
        $array = explode($search, $str, 2);
        return isset($array[1]) ? UTF8::strlen($array[0]) : false;
    }
    $str = UTF8::substr($str, $offset);
    $pos = UTF8::strpos($str, $search);
    return $pos === false ? false : $pos + $offset;
}
开发者ID:s4urp8n,项目名称:kohana-admin,代码行数:23,代码来源:strpos.php

示例8: _strrpos

/**
 * UTF8::strrpos
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2012 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;
}
开发者ID:EhteshamMehmood,项目名称:BlogMVC,代码行数:23,代码来源:strrpos.php

示例9: create_filename

 /**
  * Create new filename
  *
  * @param $filename
  * @param $generate_uniq_filename
  *
  * @return string
  */
 public static function create_filename($filename, $generate_uniq_filename = false)
 {
     $path_parts = pathinfo($filename);
     if ($path_parts['extension']) {
         $path_parts['extension'] = '.' . $path_parts['extension'];
     }
     if ($generate_uniq_filename) {
         return sha1(uniqid(null, true)) . $path_parts['extension'];
     }
     $filename = Inflector::slug($path_parts['filename'], '_');
     $filename = $filename . '_' . uniqid();
     $filename = UTF8::substr($filename, 0, 250);
     return $filename . $path_parts['extension'];
 }
开发者ID:eok8177,项目名称:shopCMS,代码行数:22,代码来源:File.php

示例10: limit_chars

 /**
  * Limits a phrase to a given number of characters.
  *
  * @param   string   phrase to limit characters of
  * @param   integer  number of characters to limit to
  * @param   string   end character or entity
  * @param   boolean  enable or disable the preservation of words while limiting
  * @return  string
  */
 public static function limit_chars($str, $limit = 100, $end_char = NULL, $preserve_words = FALSE)
 {
     $end_char = $end_char === NULL ? '&#8230;' : $end_char;
     $limit = (int) $limit;
     if (trim($str) === '' or UTF8::strlen($str) <= $limit) {
         return $str;
     }
     if ($limit <= 0) {
         return $end_char;
     }
     if ($preserve_words == FALSE) {
         return rtrim(UTF8::substr($str, 0, $limit)) . $end_char;
     }
     preg_match('/^.{' . ($limit - 1) . '}\\S*/us', $str, $matches);
     return rtrim($matches[0]) . (strlen($matches[0]) == strlen($str) ? '' : $end_char);
 }
开发者ID:Normull,项目名称:core,代码行数:25,代码来源:text.php

示例11: _strcspn

/**
 * UTF8::strcspn
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2012 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 ($offset !== 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;
}
开发者ID:Wildboard,项目名称:WbWebApp,代码行数:26,代码来源:strcspn.php

示例12: _strpos

/**
 * UTF8::strpos
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2010 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strpos($str, $search, $offset = 0)
{
	$offset = (int) $offset;

	if (UTF8::is_ascii($str) AND UTF8::is_ascii($search))
		return strpos($str, $search, $offset);

	if ($offset == 0)
	{
		$array = explode($search, $str, 2);
		return isset($array[1]) ? UTF8::strlen($array[0]) : FALSE;
	}

	$str = UTF8::substr($str, $offset);
	$pos = UTF8::strpos($str, $search);
	return ($pos === FALSE) ? FALSE : ($pos + $offset);
}
开发者ID:nevermlnd,项目名称:cv,代码行数:26,代码来源:strpos.php

示例13: limit_chars

 /**
  * Limits a phrase to a given number of characters.
  *
  *     $text = Text::limit_chars($text);
  *
  * @param   string   phrase to limit characters of
  * @param   integer  number of characters to limit to
  * @param   string   end character or entity
  * @param   boolean  enable or disable the preservation of words while limiting
  * @return  string
  * @uses    UTF8::strlen
  */
 public static function limit_chars($str, $limit = 100, $end_char = NULL, $preserve_words = FALSE)
 {
     $end_char = $end_char === NULL ? '…' : $end_char;
     $limit = (int) $limit;
     if (trim($str) === '' or UTF8::strlen($str) <= $limit) {
         return $str;
     }
     if ($limit <= 0) {
         return $end_char;
     }
     if ($preserve_words === FALSE) {
         return rtrim(UTF8::substr($str, 0, $limit)) . $end_char;
     }
     // Don't preserve words. The limit is considered the top limit.
     // No strings with a length longer than $limit should be returned.
     if (!preg_match('/^.{0,' . $limit . '}\\s/us', $str, $matches)) {
         return $end_char;
     }
     return rtrim($matches[0]) . (strlen($matches[0]) === strlen($str) ? '' : $end_char);
 }
开发者ID:jshaw86,项目名称:core,代码行数:32,代码来源:text.php

示例14: action_zhuz

 public function action_zhuz()
 {
     $zhuz_type = $this->request->param('id', 'old');
     switch ($zhuz_type) {
         case 'old':
             $id = 6;
             break;
         case 'mid':
             $id = 3;
             break;
         case 'jr':
             $id = 4;
             break;
     }
     $all = ORM::factory('Zhuze')->where('parent_id', '=', $id)->order_by('name_' . strtolower(I18n::lang()))->find_all();
     $words = array();
     if (count($all) > 0) {
         $letter = 'А';
         foreach ($all as $one) {
             if (UTF8::strtoupper(UTF8::substr($one->name, 0, 1)) != $letter) {
                 $letter = UTF8::strtoupper(UTF8::substr($one->name, 0, 1));
             }
             $words[$letter][] = array('letter' => UTF8::strtoupper(UTF8::substr($one->name, 0, 1)), 'word' => $one->name, 'id' => $one->id_publication);
         }
     }
     //var_dump($words);
     $this->add_cumb(i18n::get('Шежире – древо единства казахов'), 'shezhire');
     if ($zhuz_type == 'old') {
         $this->add_cumb(i18n::get('Старший жуз'), '');
     } elseif ($zhuz_type == 'mid') {
         $this->add_cumb(i18n::get('Средний жуз'), '');
     } else {
         $this->add_cumb(i18n::get('Младший жуз'), '');
     }
     $this->set('nomer', 0);
     $this->set('zhuz', $zhuz_type);
     $this->set('words', $words);
 }
开发者ID:HappyKennyD,项目名称:teest,代码行数:38,代码来源:Shezhire.php

示例15: 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);
 }
开发者ID:ZerGabriel,项目名称:cms-1,代码行数:43,代码来源:basic.php


注:本文中的UTF8::substr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。