本文整理汇总了PHP中utf8::strToUtf8方法的典型用法代码示例。如果您正苦于以下问题:PHP utf8::strToUtf8方法的具体用法?PHP utf8::strToUtf8怎么用?PHP utf8::strToUtf8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utf8
的用法示例。
在下文中一共展示了utf8::strToUtf8方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: nc_win2utf
function nc_win2utf($str)
{
if (extension_loaded('mbstring')) {
return mb_convert_encoding($str, "UTF-8", "cp1251");
}
if (extension_loaded('iconv')) {
return iconv('cp1251', 'UTF-8', $str);
}
global $_UTFConverter;
if (!$_UTFConverter) {
require_once "utf8/utf8.class.php";
$_UTFConverter = new utf8(CP1251);
}
return $_UTFConverter->strToUtf8($str);
}
示例2: while
$f = 0;
while ($row = mysql_fetch_array($resultados)) {
$f++;
echo '{
';
$ruta = 'img=../../repositorio/originales/' . $row['imagen'] . '&id_imagen=' . $row['id_imagen'] . '&id_palabra=' . $row['id_palabra'] . '&id_idioma=' . $id_language;
$encript->encriptar($ruta, 1);
$ruta_img = 'size=' . $thumbnailsize . '&ruta=../../repositorio/originales/' . $row['imagen'];
$encript->encriptar($ruta_img, 1);
//OJO uno(1) es para encriptar variables para URL
echo '"imagePNGURL": "http://' . $url_dominio . '/repositorio/originales/' . $row['imagen'] . '",';
if ($id_language > 0) {
switch ($id_language) {
case 1:
//RUSO
$word = $utfConverter_ru->strToUtf8($row['traduccion']);
break;
case 3:
//ARABE
$word = $utfConverter->strToUtf8($row['traduccion']);
break;
case 5:
//BULGARO
$word = $utfConverter_ru->strToUtf8($row['traduccion']);
break;
default:
$word = $row['traduccion'];
break;
}
$id_tipo_palabra = $row['id_tipo_palabra'];
echo '"name": "' . $word . '", "wordTYPE": "' . $id_tipo_palabra . '",';
示例3: convert
/**
* Convert a string from one charset to another.
* Uses mbstring and iconv functions if possible
*
* @param string Input string
* @param string Suspected charset of the input string
* @param string Target charset to convert to; defaults to RCMAIL_CHARSET
*
* @return string Converted string
*/
public static function convert($str, $from, $to = null)
{
static $iconv_options = null;
static $mbstring_loaded = null;
static $mbstring_list = null;
static $conv = null;
$to = empty($to) ? strtoupper(RCMAIL_CHARSET) : $to;
$from = self::parse($from);
// It is a common case when UTF-16 charset is used with US-ASCII content (#1488654)
// In that case we can just skip the conversion (use UTF-8)
if ($from == 'UTF-16' && !preg_match('/[^\\x00-\\x7F]/', $str)) {
$from = 'UTF-8';
}
if ($from == $to || empty($str) || empty($from)) {
return $str;
}
// convert charset using iconv module
if (function_exists('iconv') && $from != 'UTF7-IMAP' && $to != 'UTF7-IMAP') {
if ($iconv_options === null) {
// ignore characters not available in output charset
$iconv_options = '//IGNORE';
if (iconv('', $iconv_options, '') === false) {
// iconv implementation does not support options
$iconv_options = '';
}
}
// throw an exception if iconv reports an illegal character in input
// it means that input string has been truncated
set_error_handler(array('rcube_charset', 'error_handler'), E_NOTICE);
try {
$_iconv = iconv($from, $to . $iconv_options, $str);
} catch (ErrorException $e) {
$_iconv = false;
}
restore_error_handler();
if ($_iconv !== false) {
return $_iconv;
}
}
if ($mbstring_loaded === null) {
$mbstring_loaded = extension_loaded('mbstring');
}
// convert charset using mbstring module
if ($mbstring_loaded) {
$aliases['WINDOWS-1257'] = 'ISO-8859-13';
if ($mbstring_list === null) {
$mbstring_list = mb_list_encodings();
$mbstring_list = array_map('strtoupper', $mbstring_list);
}
$mb_from = $aliases[$from] ? $aliases[$from] : $from;
$mb_to = $aliases[$to] ? $aliases[$to] : $to;
// return if encoding found, string matches encoding and convert succeeded
if (in_array($mb_from, $mbstring_list) && in_array($mb_to, $mbstring_list)) {
if (mb_check_encoding($str, $mb_from) && ($out = mb_convert_encoding($str, $mb_to, $mb_from))) {
return $out;
}
}
}
// convert charset using bundled classes/functions
if ($to == 'UTF-8') {
if ($from == 'UTF7-IMAP') {
if ($_str = self::utf7imap_to_utf8($str)) {
return $_str;
}
} else {
if ($from == 'UTF-7') {
if ($_str = self::utf7_to_utf8($str)) {
return $_str;
}
} else {
if ($from == 'ISO-8859-1' && function_exists('utf8_encode')) {
return utf8_encode($str);
} else {
if (class_exists('utf8')) {
if (!$conv) {
$conv = new utf8($from);
} else {
$conv->loadCharset($from);
}
if ($_str = $conv->strToUtf8($str)) {
return $_str;
}
}
}
}
}
}
// encode string for output
if ($from == 'UTF-8') {
// @TODO: we need a function for UTF-7 (RFC2152) conversion
//.........这里部分代码省略.........