本文整理汇总了PHP中utf8::transcode方法的典型用法代码示例。如果您正苦于以下问题:PHP utf8::transcode方法的具体用法?PHP utf8::transcode怎么用?PHP utf8::transcode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utf8
的用法示例。
在下文中一共展示了utf8::transcode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Footer
/**
* page footer
* @see included/fpdf.php
*/
function Footer()
{
global $context;
// go to 1.5 cm from bottom
$this->SetY(-15);
// select Arial italic 8
$this->SetFont('Times', '', 8);
// print centered page number
$this->SetTextColor(0, 0, 0);
$this->Cell(0, 4, 'Page ' . $this->PageNo() . '/{nb}', 0, 1, 'C');
// we are proud of it
$this->SetTextColor(0, 0, 180);
$this->Cell(0, 4, utf8::to_iso8859(utf8::transcode(i18n::s('PDF export created by YACS'), TRUE)), 0, 0, 'C', 0, 'http://www.yacs.fr/');
}
示例2: clean
/**
* suppress tags and codes from a string
*
* This function will remove any yacs code, and also any html tag, from the input string.
*
* @param string a label to check
* @param allowed html tags
* @return a clean string
*/
function clean($label, $allowed = '')
{
// strip all yacs codes
$label = preg_replace(array('/\\[(.*?)\\]/s', '/\\[\\/(.*?)\\]/s'), ' ', $label);
// reintroduce new lines
$label = preg_replace('/<br\\s*\\/>/i', "\n", $label);
// make some room around titles, paragraphs, and divisions
$label = preg_replace('/<(code|div|h1|h2|h3|ol|li|p|pre|ul)>/i', ' <$1>', $label);
$label = preg_replace('#</(code|div|h1|h2|h3|ol|li|p|pre|ul)>#i', '</$1> ', $label);
// strip all html tags and encode
$label = strip_tags($label, $allowed);
// transform Unicode entities
$label = utf8::transcode($label);
// strip all html tags and encode
return encode_field($label);
}
示例3: array
Safe::header("icy-notice2: provided by a YACS server<BR>");
Safe::header("icy-pub: 1");
// name
$name = array();
if ($value = implode(' & ', @$data['comments_html']['artist'])) {
$name[] = $value;
}
if ($value = implode(', ', @$data['comments_html']['title'])) {
$name[] = $value;
}
if ($name = implode(' - ', $name)) {
Safe::header("icy-name: " . utf8::to_iso8859(utf8::transcode($name)));
}
// genre
if ($value = implode(', ', @$data['comments_html']['genre'])) {
Safe::header("icy-genre: " . utf8::to_iso8859(utf8::transcode($value)));
}
// audio bitrate
if ($value = @$data['audio']['bitrate']) {
Safe::header("icy-br: " . substr($value, 0, -3));
}
// this server
Safe::header("icy-url: " . $context['url_to_home'] . $context['url_to_root']);
}
// serve the right type
Safe::header('Content-Type: ' . Files::get_mime_type($item['file_name']));
// suggest a name for the saved file
$file_name = utf8::to_ascii($item['file_name']);
Safe::header('Content-Disposition: attachment; filename="' . str_replace('"', '', $file_name) . '"');
// we accepted (limited) range requests
Safe::header('Accept-Ranges: bytes');
示例4: build
//.........这里部分代码省略.........
// process every table row
while ($row = SQL::fetch($rows)) {
// not always the first column
$index = 0;
foreach ($row as $name => $value) {
$index++;
// skip dates and links
if ($index == 1 && $table['with_zoom'] != 'N') {
continue;
}
// glue cells
if ($text) {
$text .= $separator;
}
// clean spaces
$label = trim(preg_replace('/\\s/', ' ', $value));
// encode in iso8859
$label = utf8::to_iso8859($label);
// escape quotes to preserve them in the data
$label = str_replace('"', '""', $label);
// quote data
if (preg_match('/[^a-zA-Z0-9\\,\\.\\-_]/', $label)) {
$text .= '"' . $label . '"';
} else {
$text .= $label;
}
// only first column
break;
}
}
return $text;
// produce a raw table
// produce a raw table
case 'raw':
// comma separated values
$separator = ",";
// process every table row
while ($row = SQL::fetch($rows)) {
// one cell at a time
$index = 0;
foreach ($row as $name => $value) {
// glue cells
if ($index++) {
$text .= $separator;
}
// clean spaces
$label = trim(preg_replace('/\\s/', ' ', $value));
// encode in iso8859
$label = utf8::to_iso8859($label);
// escape quotes to preserve them in the data
$label = str_replace('"', '""', $label);
// make a link if this is a reference
if ($index == 0 && $table['with_zoom'] == 'Y') {
$label = $context['url_to_home'] . $context['url_to_root'] . $label;
}
// quote data
if (preg_match('/[^a-zA-Z0-9\\-_]/', $label)) {
$text .= '"' . $label . '"';
} else {
$text .= $label;
}
}
// new line
$text .= "\n";
}
return $text;
// a simple table
// a simple table
case 'simple':
$text .= Skin::table_prefix('table');
// columns headers
$index = 0;
while ($field = SQL::fetch_field($rows)) {
$cells[] = ucfirst($field->name);
}
$text .= Skin::table_row($cells, 'header');
// other rows
while ($row = SQL::fetch_row($rows)) {
$text .= Skin::table_row($row, $count++);
}
$text .= Skin::table_suffix();
return $text;
// xml table
// xml table
case 'xml':
$text = '';
while ($row = SQL::fetch($rows)) {
$text .= ' <item>' . "\n";
foreach ($row as $name => $value) {
$type = preg_replace('/[^a-z0-9]+/i', '_', $name);
if (preg_match('/^[^a-z]/i', $type)) {
$type = '_' . $type;
}
$text .= ' <' . $type . '>' . preg_replace('/&(?!(amp|#\\d+);)/i', '&', utf8::transcode(str_replace(array('left=', 'right='), '', $value))) . '</' . $type . '>' . "\n";
}
$text .= ' </item>' . "\n\n";
}
return '<?xml version="1.0" encoding="' . $context['charset'] . '"?>' . "\n" . '<items>' . "\n" . $text . '</items>' . "\n";
}
}
示例5: while
/**
* transcode multi-byte characters to HTML representations for Unicode
*
* This function is aiming to preserve Unicode characters through storage in a ISO-8859-1 compliant system.
*
* Every multi-byte UTF-8 character is transformed to its equivalent HTML numerical entity (eg, &#4568;)
* that may be handled safely by PHP and by MySQL.
*
* Of course, this solution does not allow for full-text search in the database and therefore, is not a
* definitive solution to internationalization issues.
* It does enable, however, practical use of Unicode to build pages in foreign languages.
*
* Also, this function transforms HTML entities into their equivalent Unicode entities.
* For example, w.bloggar posts pages using HTML entities.
* If you have to modify these pages using web forms, you would like to get UTF-8 instead.
*
* @link http://www.evolt.org/article/A_Simple_Character_Entity_Chart/17/21234/ A Simple Character Entity Chart
*
* @param mixed the original UTF-8 string, or an array
* @return a string acceptable in an ISO-8859-1 storage system (ie., PHP4 + MySQL 3)
*/
public static function &to_unicode($input)
{
global $context;
// transcode arrays as well
if (is_array($input)) {
utf8::to_unicode_recursively($input);
$output = $input;
return $output;
}
// scan the whole string
$output = '';
$index = 0;
$tick = 0;
while ($index < strlen($input)) {
// for jumbo pages --observed 167 seconds processing time for 414kbyte input
$tick++;
if (!($tick % 25000)) {
Safe::set_time_limit(30);
}
// look at one char
$char = ord($input[$index]);
// one byte (0xxxxxxx)
if ($char < 0x80) {
// some chars may be undefined
$output .= chr($char);
$index += 1;
// two bytes (110xxxxx 10xxxxxx)
} elseif ($char < 0xe0) {
// strip weird sequences (eg, C0 80 -> NUL)
if ($value = $char % 0x20 * 0x40 + ord($input[$index + 1]) % 0x40) {
$output .= '&#' . $value . ';';
}
$index += 2;
// three bytes (1110xxxx 10xxxxxx 10xxxxxx) example: euro sign = \xE2\x82\xAC -> €
} elseif ($char < 0xf0) {
// strip weird sequences
if ($value = $char % 0x10 * 0x1000 + ord($input[$index + 1]) % 0x40 * 0x40 + ord($input[$index + 2]) % 0x40) {
$output .= '&#' . $value . ';';
}
$index += 3;
// four bytes (11110xxx 10xxxxxx 10xxxxxx 10xxxxxx)
} elseif ($char < 0xf8) {
// strip weird sequences
if ($value = $char % 0x8 * 0x40000 + ord($input[$index + 1]) % 0x40 * 0x1000 + ord($input[$index + 2]) % 0x40 * 0x40 + ord($input[$index + 3]) % 0x40) {
$output .= '&#' . $value . ';';
}
$index += 4;
// five bytes (111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx)
} elseif ($char < 0xfc) {
// strip weird sequences
if ($value = $char % 0x4 * 0x1000000 + ord($input[$index + 1]) % 0x40 * 0x40000 + ord($input[$index + 2]) % 0x40 * 0x1000 + ord($input[$index + 3]) % 0x40 * 0x40 + ord($input[$index + 4]) % 0x40) {
$output .= '&#' . $value . ';';
}
$index += 5;
// six bytes (1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx)
} else {
// strip weird sequences
if ($value = $char % 0x2 * 0x40000000 + ord($input[$index + 1]) % 0x40 * 0x1000000 + ord($input[$index + 2]) % 0x40 * 0x40000 + ord($input[$index + 3]) % 0x40 * 0x1000 + ord($input[$index + 4]) % 0x40 * 0x40 + ord($input[$index + 4]) % 0x40) {
$output .= '&#' . $value . ';';
}
$index += 6;
}
}
// transcode explicit unicode entities %u2019 -> ’
$output = preg_replace_callback('/%u([0-9a-z]{4})/is', function ($matches) {
return '&#' . hexdec($matches[1]);
}, $output);
// transcode HTML entities to Unicode entities
$output =& utf8::transcode($output);
// translate extended ISO8859-1 chars, if any, to utf-8
$output = utf8_encode($output);
// return the translated string
return $output;
}
示例6: trim
/**
* get some introductory text from an article
*
* This function is used to introduce comments, or any sub-item related to an anchor.
* Compared to the standard anchor implementation, this one adds the ability to handle overlay data.
*
* If there is some introductory text, it is used. Else the description text is used instead.
* The number of words is capped in both cases.
*
* Also, the number of remaining words is provided.
*
* Following variants may be selected to adapt to various situations:
* - 'basic' - strip every tag, we want almost plain ASCII - maybe this will be send in a mail message
* - 'hover' - some text to be displayed while hovering a link
* - 'quote' - strip most HTML tags
* - 'teaser' - limit the number of words, tranform YACS codes, and link to permalink
*
* @see shared/anchor.php
*
* @param string an optional variant, including
* @return NULL, of some text
*/
function &get_teaser($variant = 'basic')
{
global $context;
// no item bound
if (!isset($this->item['id'])) {
$text = NULL;
return $text;
}
// the text to be returned
$text = '';
// use the introduction field, if any
if ($this->item['introduction']) {
$text = trim($this->item['introduction']);
// may be rendered as an empty strings
if ($variant != 'hover') {
// remove toc and toq codes
$text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
// render all codes
if (is_callable(array('Codes', 'beautify'))) {
$text = Codes::beautify($text, $this->item['options']);
}
}
// combine with description
if ($variant == 'quote') {
$text .= BR . BR;
}
}
// use overlay data, if any
if (!$text) {
if (!isset($this->overlay) && isset($this->item['overlay'])) {
$this->overlay = Overlay::load($this->item, 'article:' . $this->item['id']);
}
if (is_object($this->overlay)) {
$text .= $this->overlay->get_text('list', $this->item);
}
}
// use the description field, if any
$in_description = FALSE;
if (!$text && $variant != 'hover') {
$text .= trim($this->item['description']);
$in_description = TRUE;
// remove toc and toq codes
$text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
// render all codes
if ($variant == 'teaser' && is_callable(array('Codes', 'beautify'))) {
$text = Codes::beautify($text, $this->item['options']);
}
}
// turn html entities to unicode entities
$text = utf8::transcode($text);
// now we have to process the provided text
switch ($variant) {
// strip everything
case 'basic':
default:
// strip every HTML and limit the size
if (is_callable(array('Skin', 'strip'))) {
$text = Skin::strip($text, 70, NULL, '');
}
// done
return $text;
// some text for pop-up panels
// some text for pop-up panels
case 'hover':
// strip every HTML and limit the size
if (is_callable(array('Skin', 'strip'))) {
$text = Skin::strip($text, 70, NULL, '');
}
// ensure we have some text
if (!$text) {
$text = i18n::s('View the page');
}
// mention shortcut to article
if (Surfer::is_associate()) {
$text .= ' [article=' . $this->item['id'] . ']';
}
// done
return $text;
//.........这里部分代码省略.........
示例7: trim
/**
* get some introductory text from a section
*
* This function is used to introduce comments, or any sub-item related to an anchor.
* Compared to the standard anchor implementation, this one adds the ability to handle overlay data.
*
* If there is some introductory text, it is used. Else the description text is used instead.
* The number of words is capped in both cases.
*
* Also, the number of remaining words is provided.
*
* Following variants may be selected to adapt to various situations:
* - 'basic' - strip every tag, we want almost plain ASCII - maybe this will be send in a mail message
* - 'hover' - some text to be displayed while hovering a link
* - 'quote' - transform YACS codes, then strip most HTML tags
* - 'teaser' - limit the number of words, tranform YACS codes, and link to permalink
*
* @see shared/anchor.php
*
* @param string an optional variant
* @return NULL, of some text
*/
function &get_teaser($variant = 'basic')
{
global $context;
// nothing to do
if (!isset($this->item['id'])) {
$text = NULL;
return $text;
}
// the text to be returned
$text = '';
// use the introduction field, if any
if ($this->item['introduction']) {
$text = trim($this->item['introduction']);
// may be rendered as an empty strings
if ($variant != 'hover') {
// remove toc and toq codes
$text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
// render all codes
if (is_callable(array('Codes', 'beautify'))) {
$text =& Codes::beautify($text, $this->item['options']);
}
}
// remove most html
if ($variant != 'teaser') {
$text = xml::strip_visible_tags($text);
}
// combine with description
if ($variant == 'quote') {
$text .= BR . BR;
}
}
// use overlay data, if any
if (!$text) {
$overlay = Overlay::load($this->item, 'section:' . $this->item['id']);
if (is_object($overlay)) {
$text .= $overlay->get_text('list', $this->item);
}
}
// use the description field, if any
$in_description = FALSE;
if (!$text && $variant != 'hover' || $variant == 'quote') {
$text .= trim($this->item['description']);
$in_description = TRUE;
// remove toc and toq codes
$text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
// render all codes
if (is_callable(array('Codes', 'beautify'))) {
$text =& Codes::beautify($text, $this->item['options']);
}
// remove most html
$text = xml::strip_visible_tags($text);
}
// turn html entities to unicode entities
$text =& utf8::transcode($text);
// now we have to process the provided text
switch ($variant) {
// strip everything
case 'basic':
default:
// remove most html
$text = xml::strip_visible_tags($text);
// limit the number of words
$text =& Skin::cap($text, 70);
// done
return $text;
// some text for pop-up panels
// some text for pop-up panels
case 'hover':
// remove most html
$text = xml::strip_visible_tags($text);
// limit the number of words
$text =& Skin::strip($text, 70);
// ensure we have some text
if (!$text) {
$text = i18n::s('View the page');
}
// mention shortcut to section
if (Surfer::is_associate()) {
//.........这里部分代码省略.........
示例8: elseif
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
// react to overlaid POST by a overlaid response
global $render_overlaid;
if ($render_overlaid) {
$context['text'] .= '<div class="hidden require-overlaid"></div>' . "\n";
}
// target user statut doesn't allow MP, except from associates
if (!Surfer::is_associate() && ($overlay->attributes['user_status'] == 'donotdisturb' || $overlay->attributes['user_status'] == 'anonymous' || $item['without_alerts'] == 'Y')) {
$context['text'] .= sprintf(i18n::s('Sorry, %s wish not to receive private message'), $item['nick_name']);
render_skin();
finalize_page(TRUE);
}
// the new thread
$article = array();
$article['anchor'] = $anchor;
$article['title'] = isset($_REQUEST['title']) ? $_REQUEST['title'] : utf8::transcode(Skin::build_date(gmstrftime('%Y-%m-%d %H:%M:%S GMT'), 'full'));
$article['active_set'] = 'N';
// this is private
$article['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S');
// no review is required
$article['options'] = 'view_as_zic_pm';
// include some overlay
$overlay = Overlay::bind('thread');
$article['overlay'] = $overlay->save();
$article['overlay_id'] = $overlay->get_id();
// ensure everything is positioned as expected
Surfer::empower();
// post the new thread
if (!($article['id'] = Articles::post($article))) {
Logger::error(i18n::s('Impossible to add a page.'));
} else {
示例9: elseif
/**
* lookup a localised string in an array
*
* This can be used to parse manifest files for example.
*
* This function also transcode HTML entities to Unicode entities, if any.
*
* @param array the array containing localized strings
* @param string the label identifying string
* @param string desired language, if any
* @return string the localized string, if any
*/
public static function &l(&$strings, $name, $forced = '')
{
global $context;
// sanity check
if (!$name) {
return $name;
}
// select a string
if ($forced && ($key = $name . '_' . $forced) && array_key_exists($key, $strings)) {
$text = $strings[$key];
} elseif (($key = $name . '_' . $context['language']) && array_key_exists($key, $strings)) {
$text = $strings[$key];
} elseif (($key = $name . '_en') && array_key_exists($key, $strings)) {
$text = $strings[$key];
} elseif (array_key_exists($name, $strings)) {
$text = $strings[$name];
} else {
$text = $name;
if ($context['with_debug'] == 'Y') {
logger::remember('i18n/i18n.php: ' . $name . ' is not localized', '', 'debug');
}
}
// the file may be absent during updates
Safe::load('shared/utf8.php');
// transcode to utf8
if (isset($context['charset']) && $context['charset'] == 'utf-8' && is_callable(array('utf8', 'transcode'))) {
$text =& utf8::transcode($text);
}
return $text;
}