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


PHP UTF8类代码示例

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


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

示例1: text

 /**
  * Print the message
  */
 function text($indexName, $extra = FALSE)
 {
     include_once "MISC.php";
     include_once "../UTF8.php";
     $utf8 = new UTF8();
     $arrays = $this->loadArrays();
     $string = $arrays[$indexName];
     $string = $extra ? preg_replace("/###/", $utf8->smartUtf8_decode($extra), $string) : preg_replace("/###/", "", $string);
     return MISC::p($utf8->encodeUtf8($string), "success", "center");
 }
开发者ID:hasantayyar,项目名称:osbib,代码行数:13,代码来源:SUCCESS.php

示例2: action_tag

 /**
  * Retrieve a JSON object containing autocomplete suggestions for existing users.
  */
 public function action_tag()
 {
     $string = $this->request->param('string', FALSE);
     $type = $this->request->param('type', 'blog');
     // The user enters a comma-separated list of tags. We only autocomplete the last tag.
     $tags_typed = Tags::explode($string);
     $tag_last = UTF8::strtolower(array_pop($tags_typed));
     $matches = array();
     if (!empty($tag_last)) {
         $query = DB::select('name')->from('tags')->where('name', 'LIKE', $tag_last . '%')->where('type', '=', $type);
         // Do not select already entered terms.
         if (!empty($tags_typed)) {
             $query->where('name', 'NOT IN', $tags_typed);
         }
         $result = $query->limit('10')->execute();
         $prefix = count($tags_typed) ? implode(', ', $tags_typed) . ', ' : '';
         foreach ($result as $tag) {
             $n = $tag['name'];
             // Tag names containing commas or quotes must be wrapped in quotes.
             if (strpos($tag['name'], ',') !== FALSE or strpos($tag['name'], '"') !== FALSE) {
                 $n = '"' . str_replace('"', '""', $tag['name']) . '"';
             } else {
                 $matches[$prefix . $n] = Text::plain($tag['name']);
             }
         }
     }
     $this->response->body(JSON::encode($matches));
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:31,代码来源:autocomplete.php

示例3: update

 /**
  * Overload Sprig::update() to save revision change
  * @param bump  whether to bump the version number
  */
 public function update($bump = TRUE)
 {
     Kohana::$log->add(Kohana::DEBUG, 'Executing Versioned_Sprig::update');
     $updated = FALSE;
     foreach ($this->_fields as $field => $object) {
         if ($object instanceof Sprig_Field_Tracked and $this->changed($field)) {
             $this->comment = UTF8::ucwords($object->label) . ' changed from "' . $this->_original[$field] . '" to "' . $this->_changed[$field] . '".';
         }
         if ($object instanceof Sprig_Field_Versioned and $this->changed($field) and $bump) {
             $diff = '';
             if ($this->version != 0) {
                 $diff = Versioned::diff($this->_original[$field], $this->_changed[$field]);
                 $diff = Versioned::clean_array($diff);
                 $diff = serialize($diff);
             }
             $this->version++;
             $revision = Sprig::factory($this->_model . '_revision');
             $revision->values(array('entry' => $this->id, 'version' => $this->version, 'editor' => $this->editor, 'diff' => $diff));
             $revision->comments = $this->comments;
             $revision->create();
             $updated = TRUE;
             $this->comments = array();
         }
     }
     if (!$updated and count($this->comments) > 0) {
         $revision = Sprig::factory($this->_model . '_revision');
         $revision->entry = $this->id;
         $revision->version = $this->version;
         $revision->load();
         $revision->comments = array_merge($revision->comments, $this->comments);
         $revision->update();
     }
     return parent::update();
 }
开发者ID:vimofthevine,项目名称:versioned,代码行数:38,代码来源:sprig.php

示例4: clean

 public static function clean($var, $charset = NULL)
 {
     if (!$charset) {
         // Use the application character set
         $charset = JsonApiApplication::$charset;
     }
     if (is_array($var) or is_object($var)) {
         foreach ($var as $key => $val) {
             // Recursion!
             $var[UTF8::clean($key)] = UTF8::clean($val);
         }
     } elseif (is_string($var) and $var !== "") {
         // Remove control characters
         $var = UTF8::strip_ascii_ctrl($var);
         if (!UTF8::is_ascii($var)) {
             // Temporarily save the mb_substitute_character() value into a variable
             $mb_substitute_character = mb_substitute_character();
             // Disable substituting illegal characters with the default '?' character
             mb_substitute_character("none");
             // convert encoding, this is expensive, used when $var is not ASCII
             $var = mb_convert_encoding($var, $charset, $charset);
             // Reset mb_substitute_character() value back to the original setting
             mb_substitute_character($mb_substitute_character);
         }
     }
     return $var;
 }
开发者ID:benshez,项目名称:DreamWeddingCeremonies,代码行数:27,代码来源:UTF8.php

示例5: utf8_to_ascii_test

 public function utf8_to_ascii_test()
 {
     $this->assert_equal("Te glossa mou edosan ellenike", UTF8::transliterate_to_ascii("Τη γλώσσα μου έδωσαν ελληνική"));
     $this->assert_equal("Na bierieghu pustynnykh voln", UTF8::transliterate_to_ascii("На берегу пустынных волн"));
     $this->assert_equal("vepxis tqaosani shot`a rust`aveli", UTF8::transliterate_to_ascii("ვეპხის ტყაოსანი შოთა რუსთაველი"));
     $this->assert_equal("WoNengTunXiaBoLiErBuShangShenTi", UTF8::transliterate_to_ascii("我能吞下玻璃而不伤身体"));
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:7,代码来源:Transliterate_Helper_Test.php

示例6: _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

示例7: _trim

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

示例8: _str_ireplace

/**
 * UTF8::str_ireplace
 *
 * @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_ireplace($search, $replace, $str, & $count = NULL)
{
	if (UTF8::is_ascii($search) AND UTF8::is_ascii($replace) AND UTF8::is_ascii($str))
		return str_ireplace($search, $replace, $str, $count);

	if (is_array($str))
	{
		foreach ($str as $key => $val)
		{
			$str[$key] = UTF8::str_ireplace($search, $replace, $val, $count);
		}
		return $str;
	}

	if (is_array($search))
	{
		$keys = array_keys($search);

		foreach ($keys as $k)
		{
			if (is_array($replace))
			{
				if (array_key_exists($k, $replace))
				{
					$str = UTF8::str_ireplace($search[$k], $replace[$k], $str, $count);
				}
				else
				{
					$str = UTF8::str_ireplace($search[$k], '', $str, $count);
				}
			}
			else
			{
				$str = UTF8::str_ireplace($search[$k], $replace, $str, $count);
			}
		}
		return $str;
	}

	$search = UTF8::strtolower($search);
	$str_lower = UTF8::strtolower($str);

	$total_matched_strlen = 0;
	$i = 0;

	while (preg_match('/(.*?)'.preg_quote($search, '/').'/s', $str_lower, $matches))
	{
		$matched_strlen = strlen($matches[0]);
		$str_lower = substr($str_lower, $matched_strlen);

		$offset = $total_matched_strlen + strlen($matches[1]) + ($i * (strlen($replace) - 1));
		$str = substr_replace($str, $replace, $offset, strlen($search));

		$total_matched_strlen += $matched_strlen;
		$i++;
	}

	$count += $i;
	return $str;
}
开发者ID:nevermlnd,项目名称:cv,代码行数:69,代码来源:str_ireplace.php

示例9: 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

示例10: save

 /**
  * Updates or Creates the record depending on loaded()
  *
  * @param   Validation  $validation  Validation object
  * @return  ORM
  *
  * @uses    User::active_user
  * @uses    ACL::check
  * @uses    Text::limit_words
  * @uses    Text::markup
  * @uses    Request::$client_ip
  */
 public function save(Validation $validation = NULL)
 {
     // Set some defaults
     $this->updated = time();
     $this->format = empty($this->format) ? Kohana::$config->load('inputfilter.default_format', 1) : $this->format;
     $this->author = empty($this->author) ? User::active_user()->id : $this->author;
     if (!$this->loaded()) {
         // New comment
         $this->created = $this->updated;
         $this->hostname = substr(Request::$client_ip, 0, 32);
         //set hostname only if its new comment.
         if (empty($this->status)) {
             $this->status = ACL::check('skip comment approval') ? 'publish' : 'draft';
         }
     }
     // Validate the comment's title. If not specified, extract from comment body.
     if (trim($this->title) == '' and !empty($this->body)) {
         // The body may be in any format, so:
         // 1) Filter it into HTML
         // 2) Strip out all HTML tags
         // 3) Convert entities back to plain-text.
         $this->title = Text::limit_words(trim(UTF8::clean(strip_tags(Text::markup($this->body, $this->format)))), 10, '');
         // Edge cases where the comment body is populated only by HTML tags will
         // require a default subject.
         if ($this->title == '') {
             $this->title = __('(No subject)');
         }
     }
     parent::save($validation);
     return $this;
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:43,代码来源:comment.php

示例11: 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

示例12: RefererURLBeautifier_handler

function RefererURLBeautifier_handler($target, $mother)
{
    $keyword = false;
    if (preg_match('/\\W(q|query|k|keyword|search|stext|nlia|aqa|wd)(?:=|%3D)([^&]+)/i', $mother['url'], $matches)) {
        $keyword = urldecode(rawurldecode($matches[2]));
    } else {
        if (strpos($mother['host'], 'images.google.') !== false && preg_match('/%3Fsearch%3D([^&]+)/i', $mother['url'], $matches)) {
            $keyword = urldecode(rawurldecode($matches[1]));
        } else {
            if (strpos($mother['host'], 'yahoo.') !== false && preg_match('/\\Wp=([^&]+)/i', $mother['url'], $matches)) {
                $keyword = urldecode(rawurldecode($matches[1]));
            } else {
                if (preg_match('@/search/(?:\\w+/)*([^/?]+)@i', $mother['url'], $matches)) {
                    $keyword = urldecode(rawurldecode($matches[1]));
                }
            }
        }
    }
    if (!UTF8::validate($keyword)) {
        $keyword = UTF8::correct(UTF8::bring($keyword));
    }
    $keyword = UTF16UrlDecode($keyword);
    $url = rawurldecode(substr($mother['url'], 7));
    if (!UTF8::validate($url)) {
        $url = UTF8::correct(UTF8::bring($url));
    }
    //return '<img src="http://'.$mother['host'].'/favicon.ico" width="16" height="16" alt="Favicon" onerror="this.parentNode.removeChild(this)" style="vertical-align: middle"/> ' . (($keyword) ? '<span style="font-weight: bold; color: #594">['.htmlspecialchars($keyword).']</span> ' . UTF8::lessenAsEm($url, 65 - UTF8::lengthAsEm($keyword)) : UTF8::lessenAsEm($url, 65));
    return $keyword ? '<span style="font-weight: bold; color: #594">[' . htmlspecialchars($keyword) . ']</span> ' . htmlspecialchars(UTF8::lessenAsEm($url, 70 - UTF8::lengthAsEm($keyword))) : htmlspecialchars(UTF8::lessenAsEm($url, 70));
}
开发者ID:hinablue,项目名称:TextCube,代码行数:29,代码来源:index.php

示例13: __set

 /**
  * Magic setter
  *
  * @param  string  $key
  * @param  mixed   $value
  */
 public function __set($key, $value)
 {
     switch ($key) {
         // Date of birth
         case 'dob':
             $value = Date::format(Date::DATE_SQL, $value);
             break;
             // Always lowercase e-mail
         // Always lowercase e-mail
         case 'email':
             $value = UTF8::strtolower($value);
             break;
             // Hash password
         // Hash password
         case 'password':
             $visitor = Visitor::instance();
             $value = $visitor->hash_password($value);
             break;
             // Set cleaned username when setting username
         // Set cleaned username when setting username
         case 'username':
             $this->username_clean = Text::clean($value);
             break;
     }
     parent::__set($key, $value);
 }
开发者ID:anqh,项目名称:core,代码行数:32,代码来源:user.php

示例14: 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:ortodesign,项目名称:cms,代码行数:39,代码来源:black.php

示例15: _strlen

/**
 * UTF8::strlen
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2011 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:aslijiasheng,项目名称:ciFramework,代码行数:16,代码来源:strlen.php


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