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


PHP utf8类代码示例

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


在下文中一共展示了utf8类的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);
}
开发者ID:Toushi,项目名称:flow,代码行数:40,代码来源:str_pad.php

示例2: nc_utf2win

function nc_utf2win($str)
{
    if (extension_loaded('mbstring')) {
        return mb_convert_encoding($str, "cp1251", "UTF-8");
    }
    if (extension_loaded('iconv')) {
        return iconv('UTF-8', 'cp1251', $str);
    }
    global $_UTFConverter;
    if (!$_UTFConverter) {
        require_once "utf8/utf8.class.php";
        $_UTFConverter = new utf8(CP1251);
    }
    return $_UTFConverter->utf8ToStr($str);
}
开发者ID:Blu2z,项目名称:implsk,代码行数:15,代码来源:utf8.php

示例3: set

 public function set($plugin, $keyword, $replace = array(), $pageTitle = true)
 {
     if (!($data = $this->cache->item('core_meta_tags_' . $plugin . '_' . session::item('language')))) {
         $data = array();
         $result = $this->db->query("SELECT * FROM `:prefix:core_meta_tags` WHERE `plugin`=?", array($plugin))->result();
         foreach ($result as $tags) {
             $data[$tags['keyword']]['title'] = $tags['meta_title_' . session::item('language')];
             $data[$tags['keyword']]['description'] = $tags['meta_description_' . session::item('language')];
             $data[$tags['keyword']]['keywords'] = $tags['meta_keywords_' . session::item('language')];
         }
         $this->cache->set('core_meta_tags_' . $plugin . '_' . session::item('language'), $data, 60 * 60 * 24 * 30);
     }
     foreach ($replace as $section => $array) {
         foreach ($array as $k => $v) {
             $k = '[' . $section . '.' . $k . ']';
             if (is_array($v)) {
                 $v = count($v) == 1 ? current($v) : implode(',', $v);
             }
             $data[$keyword]['title'] = utf8::str_replace($k, $v, $data[$keyword]['title']);
             $data[$keyword]['description'] = utf8::str_replace($k, $v, $data[$keyword]['description']);
             $data[$keyword]['keywords'] = utf8::str_replace($k, $v, $data[$keyword]['keywords']);
         }
     }
     if (isset($data[$keyword])) {
         if ($pageTitle) {
             view::setTitle($data[$keyword]['title']);
         } else {
             view::setMetaTitle($data[$keyword]['title']);
         }
         view::setMetaDescription($data[$keyword]['description']);
         view::setMetaKeywords($data[$keyword]['keywords']);
     }
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:33,代码来源:metatags.php

示例4: delete

 public function delete()
 {
     // Get URI vars
     $slugID = urldecode(utf8::trim(uri::segment(4)));
     // Do we have a slug ID?
     if ($slugID == '') {
         error::show404();
     }
     // Get user
     if (!($user = $this->users_model->getUser($slugID)) || !$user['active'] || !$user['verified']) {
         error::show404();
     } elseif ($user['user_id'] == session::item('user_id')) {
         router::redirect($user['slug']);
     }
     // Does user exist?
     if (!($blocked = $this->users_blocked_model->getUser($user['user_id'], true))) {
         view::setError(__('no_blocked_user', 'users_blocked'));
         router::redirect('users/blocked');
     }
     // Delete blocked user
     $this->users_blocked_model->deleteBlockedUser(session::item('user_id'), $user['user_id']);
     // Success
     view::setInfo(__('user_unblocked', 'users_blocked'));
     router::redirect(input::get('page') ? 'users/blocked' : $user['slug']);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:25,代码来源:blocked.php

示例5: zenphoto_sendmail

function zenphoto_sendmail($msg, $email_list, $subject, $message, $from_mail, $from_name, $cc_addresses, $replyTo, $html = false)
{
    $headers = sprintf('From: %1$s <%2$s>', $from_name, $from_mail) . "\n";
    if (count($cc_addresses) > 0) {
        $cclist = '';
        foreach ($cc_addresses as $cc_name => $cc_mail) {
            $cclist .= ',' . $cc_mail;
        }
        $headers .= 'Cc: ' . substr($cclist, 1) . "\n";
    }
    if ($replyTo) {
        $headers .= 'Reply-To: ' . array_shift($replyTo) . "\n";
    }
    $result = true;
    foreach ($email_list as $to_mail) {
        $result = $result && utf8::send_mail($to_mail, $subject, $message, $headers, '', $html);
    }
    if (!$result) {
        if (!empty($msg)) {
            $msg .= '<br />';
        }
        $msg .= sprintf(gettext('<code>zenphoto_sendmail</code> failed to send <em>%s</em> to one or more recipients.'), $subject);
    }
    return $msg;
}
开发者ID:ariep,项目名称:ZenPhoto20-DEV,代码行数:25,代码来源:zenphoto_sendmail.php

示例6: sendTemplate

 public function sendTemplate($keyword, $email, $tags = array(), $language = '')
 {
     loader::model('system/emailtemplates');
     if (!$language) {
         $language = config::item('language_id', 'system');
     }
     if (is_numeric($language)) {
         $language = config::item('languages', 'core', 'keywords', $language);
     } elseif (!in_array($language, config::item('languages', 'core', 'keywords'))) {
         return false;
     }
     if (!($template = config::item($keyword . '_' . $language, '_system_emails_cache'))) {
         if (!($template = $this->cache->item('core_email_template_' . $keyword . '_' . $language))) {
             $template = $this->emailtemplates_model->prepareTemplate($keyword, $language);
             if (count($template) == 3) {
                 if ($template[$keyword]['active']) {
                     $template = array('subject' => $template[$keyword]['subject'], 'message_html' => utf8::trim($template['header']['message_html'] . $template[$keyword]['message_html'] . $template['footer']['message_html']), 'message_text' => utf8::trim($template['header']['message_text'] . "\n\n" . $template[$keyword]['message_text'] . "\n\n" . $template['footer']['message_text']));
                 } else {
                     $template = 'none';
                 }
             } else {
                 error::show('Could not fetch email template from the database: ' . $keyword);
             }
             $this->cache->set('core_email_template_' . $keyword . '_' . $language, $template, 60 * 60 * 24 * 30);
         }
         config::set(array($keyword . '_' . $language => $template), '', '_system_emails_cache');
     }
     $retval = true;
     if (is_array($template) && $template) {
         $retval = $this->sendEmail($email, $template['subject'], $template['message_text'], $template['message_html'], $tags);
     }
     return $retval;
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:33,代码来源:email.php

示例7: testNumeric_to_utf8

 public function testNumeric_to_utf8()
 {
     $ns = array(0x1403, 0x1403, 0x1403);
     $a = chr(0xe1) . chr(0x90) . chr(0x83) . chr(0xe1) . chr(0x90) . chr(0x83) . chr(0xe1) . chr(0x90) . chr(0x83);
     $r = utf8::numeric_to_utf8($ns);
     $this->assertEquals($a, $r);
 }
开发者ID:nrc-cnrc,项目名称:InuktitutToolkit,代码行数:7,代码来源:utf8Test.php

示例8: _trim

/**
 * utf8::trim
 *
 * @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 _trim($str, $charlist = NULL)
{
    if ($charlist === NULL) {
        return trim($str);
    }
    return utf8::ltrim(utf8::rtrim($str, $charlist), $charlist);
}
开发者ID:kjgarza,项目名称:ushahidi,代码行数:16,代码来源:trim.php

示例9: _strlen

/**
 * utf8::strlen
 *
 * @package    Core
 * @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 _strlen($str)
{
    if (utf8::is_ascii($str)) {
        return strlen($str);
    }
    return strlen(utf8_decode($str));
}
开发者ID:ascseb,项目名称:kohana,代码行数:16,代码来源:strlen.php

示例10: __construct

 public function __construct()
 {
     parent::__construct();
     if (!config::item('news_blog', 'news') && uri::segment(1) != 'news') {
         router::redirect('news/' . utf8::substr(uri::getURI(), 5));
     }
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:7,代码来源:blog.php

示例11: 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);
 }
开发者ID:rucky2013,项目名称:kohana-php-admin,代码行数:39,代码来源:Black.php

示例12: days

 /**
  * Returns an array of the names of the days, using the current locale.
  *
  * @param   integer  left of day names
  * @return  array
  */
 public static function days($length = TRUE)
 {
     // strftime day format
     $format = $length > 3 ? '%A' : '%a';
     // Days of the week
     $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
     if (Calendar::$start_monday === TRUE) {
         // Push Sunday to the end of the days
         array_push($days, array_shift($days));
     }
     if (strpos(Kohana::config('locale.language.0'), 'en') !== 0) {
         // This is a bit awkward, but it works properly and is reliable
         foreach ($days as $i => $day) {
             // Convert the English names to i18n names
             $days[$i] = strftime($format, strtotime($day));
         }
     }
     if (is_int($length) or ctype_digit($length)) {
         foreach ($days as $i => $day) {
             // Shorten the days to the expected length
             $days[$i] = utf8::substr($day, 0, $length);
         }
     }
     return $days;
 }
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:31,代码来源:Calendar.php

示例13: normalize

 public static function normalize($string, $encoding = 'utf-8')
 {
     $string = iconv($encoding, 'ascii//translit', $string);
     $string = utf8::str_ireplace(',', '', $string);
     $string = utf8::str_ireplace('\'', '', $string);
     $string = preg_replace('/[^a-z0-9-\\+\\/_ ]/iUD', '_', $string);
     return $string;
 }
开发者ID:TdroL,项目名称:piotrszkaluba.pl,代码行数:8,代码来源:text.php

示例14: _ucfirst

/**
 * utf8::ucfirst
 *
 * @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 _ucfirst($str)
{
    if (utf8::is_ascii($str)) {
        return ucfirst($str);
    }
    preg_match('/^(.?)(.*)$/us', $str, $matches);
    return utf8::strtoupper($matches[1]) . $matches[2];
}
开发者ID:darkcolonist,项目名称:kohana234-doctrine115,代码行数:17,代码来源:ucfirst.php

示例15: _strrev

/**
 * utf8::strrev
 *
 * @package    Core
 * @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 _strrev($str)
{
    if (utf8::is_ascii($str)) {
        return strrev($str);
    }
    preg_match_all('/./us', $str, $matches);
    return implode('', array_reverse($matches[0]));
}
开发者ID:ascseb,项目名称:kohana,代码行数:17,代码来源:strrev.php


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