本文整理汇总了PHP中utf8类的典型用法代码示例。如果您正苦于以下问题:PHP utf8类的具体用法?PHP utf8怎么用?PHP utf8使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了utf8类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: request
/**
* Method that allows sending any kind of HTTP request to remote url
*
* @param string $method
* @param string $url
* @param array $headers
* @param array $data
* @return HTTP_Response
*/
public static function request($method, $url, $headers = array(), $data = array())
{
$valid_methods = array('POST', 'GET', 'PUT', 'DELETE');
$method = utf8::strtoupper($method);
if (!valid::url($url, 'http')) {
return FALSE;
}
if (!in_array($method, $valid_methods)) {
return FALSE;
}
// Get the hostname and path
$url = parse_url($url);
if (empty($url['path'])) {
// Request the root document
$url['path'] = '/';
}
// Open a remote connection
$remote = fsockopen($url['host'], 80, $errno, $errstr, 5);
if (!is_resource($remote)) {
return FALSE;
}
// Set CRLF
$CRLF = "\r\n";
$path = $url['path'];
if ($method == 'GET' and !empty($url['query'])) {
$path .= '?' . $url['query'];
}
$headers_default = array('Host' => $url['host'], 'Connection' => 'close', 'User-Agent' => 'Ushahidi Scheduler (+http://ushahidi.com/)');
$body_content = '';
if ($method != 'GET') {
$headers_default['Content-Type'] = 'application/x-www-form-urlencoded';
if (count($data) > 0) {
$body_content = http_build_query($data);
}
$headers_default['Content-Length'] = strlen($body_content);
}
$headers = array_merge($headers_default, $headers);
// Send request
$request = $method . ' ' . $path . ' HTTP/1.0' . $CRLF;
foreach ($headers as $key => $value) {
$request .= $key . ': ' . $value . $CRLF;
}
// Send one more CRLF to terminate the headers
$request .= $CRLF;
if ($body_content) {
$request .= $body_content . $CRLF;
}
fwrite($remote, $request);
$response = '';
while (!feof($remote)) {
// Get 1K from buffer
$response .= fread($remote, 1024);
}
// Close the connection
fclose($remote);
return new HTTP_Response($response, $method);
}
开发者ID:pablohernandezb,项目名称:reportachacao-server,代码行数:66,代码来源:MY_remote.php
示例17: _strcasecmp
/**
* utf8::strcasecmp
*
* @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 _strcasecmp($str1, $str2)
{
if (utf8::is_ascii($str1) and utf8::is_ascii($str2)) {
return strcasecmp($str1, $str2);
}
$str1 = utf8::strtolower($str1);
$str2 = utf8::strtolower($str2);
return strcmp($str1, $str2);
}
开发者ID:sydlawrence,项目名称:SocialFeed,代码行数:18,代码来源:strcasecmp.php
示例18: _ucwords
/**
* utf8::ucwords
*
* @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 _ucwords($str)
{
if (utf8::is_ascii($str)) {
return ucwords($str);
}
// [\x0c\x09\x0b\x0a\x0d\x20] matches form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns.
// This corresponds to the definition of a 'word' defined at http://php.net/ucwords
return preg_replace('/(?<=^|[\\x0c\\x09\\x0b\\x0a\\x0d\\x20])[^\\x0c\\x09\\x0b\\x0a\\x0d\\x20]/ue', 'utf8::strtoupper(\'$0\')', $str);
}
开发者ID:ascseb,项目名称:kohana,代码行数:18,代码来源:ucwords.php
示例19: extract
static function extract($item)
{
$keys = array();
// Only try to extract EXIF from photos
if ($item->is_photo() && $item->mime_type == "image/jpeg") {
$data = array();
require_once MODPATH . "exif/lib/exif.php";
$exif_raw = read_exif_data_raw($item->file_path(), false);
if (isset($exif_raw['ValidEXIFData'])) {
foreach (self::_keys() as $field => $exifvar) {
if (isset($exif_raw[$exifvar[0]][$exifvar[1]])) {
$value = $exif_raw[$exifvar[0]][$exifvar[1]];
if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") {
$value = utf8_encode($value);
}
$keys[$field] = utf8::clean($value);
if ($field == "DateTime") {
$time = strtotime($value);
if ($time > 0) {
$item->captured = $time;
}
} else {
if ($field == "Caption" && !$item->description) {
$item->description = $value;
}
}
}
}
}
$size = getimagesize($item->file_path(), $info);
if (is_array($info) && !empty($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
foreach (array("Keywords" => "2#025", "Caption" => "2#120") as $keyword => $iptc_key) {
if (!empty($iptc[$iptc_key])) {
$value = implode(" ", $iptc[$iptc_key]);
if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") {
$value = utf8_encode($value);
}
$keys[$keyword] = utf8::clean($value);
if ($keyword == "Caption" && !$item->description) {
$item->description = $value;
}
}
}
}
}
$item->save();
$record = ORM::factory("exif_record")->where("item_id", $item->id)->find();
if (!$record->loaded) {
$record->item_id = $item->id;
}
$record->data = serialize($keys);
$record->key_count = count($keys);
$record->dirty = 0;
$record->save();
}
开发者ID:krgeek,项目名称:gallery3,代码行数:56,代码来源:exif.php
示例20: convert_to_utf
/**
* Method to convert the content to UTF
* @note Depricated on Ofuz 0.6 and will not be abailable on further version
*/
function convert_to_utf($content)
{
include_once 'class/utf8.class.php';
$do_utf8 = new utf8();
$content = $do_utf8->convert($content, 'windows-1252', "UTF-8");
$content = $do_utf8->convert($content, 'US-ASCII', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-1', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-2', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-3', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-4', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-5', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-6', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-7', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-8', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-8-i', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-9', "UTF-8");
$content = $do_utf8->convert($content, 'ISO-8859-15', "UTF-8");
return $content;
}
开发者ID:jacquesbagui,项目名称:ofuz,代码行数:23,代码来源:.ProjectDiscuss.class.php
注:本文中的utf8类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论