本文整理汇总了PHP中SimplePie_Misc::encoding方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie_Misc::encoding方法的具体用法?PHP SimplePie_Misc::encoding怎么用?PHP SimplePie_Misc::encoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimplePie_Misc
的用法示例。
在下文中一共展示了SimplePie_Misc::encoding方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_convert_UTF16
/**
* Convert * to UTF-16
* @dataProvider toUTF16
*/
public function test_convert_UTF16($input, $expected, $encoding)
{
$encoding = SimplePie_Misc::encoding($encoding);
$this->assertEquals($expected, SimplePie_Misc::change_encoding($input, $encoding, 'UTF-16'));
}
示例2: change_encoding
/**
* Change a string from one encoding to another
*
* @param string $data Raw data in $input encoding
* @param string $input Encoding of $data
* @param string $output Encoding you want
* @return string|boolean False if we can't convert it
*/
public static function change_encoding($data, $input, $output)
{
$input = SimplePie_Misc::encoding($input);
$output = SimplePie_Misc::encoding($output);
// We fail to fail on non US-ASCII bytes
if ($input === 'US-ASCII') {
static $non_ascii_octects = '';
if (!$non_ascii_octects) {
for ($i = 0x80; $i <= 0xff; $i++) {
$non_ascii_octects .= chr($i);
}
}
$data = substr($data, 0, strcspn($data, $non_ascii_octects));
}
// This is first, as behaviour of this is completely predictable
if ($input === 'windows-1252' && $output === 'UTF-8') {
return SimplePie_Misc::windows_1252_to_utf8($data);
} elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output))) {
return $return;
} elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output))) {
return $return;
} else {
return false;
}
}
示例3: change_encoding
public static function change_encoding($data, $input, $output)
{
$input = SimplePie_Misc::encoding($input);
$output = SimplePie_Misc::encoding($output);
if ($input === 'US-ASCII') {
static $non_ascii_octects = '';
if (!$non_ascii_octects) {
for ($i = 0x80; $i <= 0xff; $i++) {
$non_ascii_octects .= chr($i);
}
}
$data = substr($data, 0, strcspn($data, $non_ascii_octects));
}
if ($input === 'windows-1252' && $output === 'UTF-8') {
return SimplePie_Misc::windows_1252_to_utf8($data);
} elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output))) {
return $return;
} elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output))) {
return $return;
} else {
return false;
}
}
示例4: change_encoding
function change_encoding($data, $input, $output)
{
$input = SimplePie_Misc::encoding($input);
$output = SimplePie_Misc::encoding($output);
// We fail to fail on non US-ASCII bytes
if ($input === 'US-ASCII') {
static $non_ascii_octects = '';
if (!$non_ascii_octects) {
for ($i = 0x80; $i <= 0xff; $i++) {
$non_ascii_octects .= chr($i);
}
}
$data = substr($data, 0, strcspn($data, $non_ascii_octects));
}
if (function_exists('iconv') && ($return = @iconv($input, $output, $data))) {
return $return;
} elseif (function_exists('mb_convert_encoding') && ($return = @mb_convert_encoding($data, $output, $input))) {
return $return;
} elseif ($input == 'windows-1252' && $output == 'UTF-8') {
return SimplePie_Misc::windows_1252_to_utf8($data);
} elseif ($input == 'UTF-8' && $output == 'windows-1252') {
return utf8_decode($data);
}
return $data;
}
示例5: change_encoding
function change_encoding($data, $input, $output)
{
$input = SimplePie_Misc::encoding($input);
$output = SimplePie_Misc::encoding($output);
// We fail to fail on non US-ASCII bytes
if ($input === 'US-ASCII')
{
static $non_ascii_octects = '';
if (!$non_ascii_octects)
{
for ($i = 0x80; $i <= 0xFF; $i++)
{
$non_ascii_octects .= chr($i);
}
}
$data = substr($data, 0, strcspn($data, $non_ascii_octects));
}
// This is first, as behaviour of this is completely predictable
if ($input === 'Windows-1252' && $output === 'UTF-8')
{
return SimplePie_Misc::windows_1252_to_utf8($data);
}
// This is second, as behaviour of this varies only with PHP version
elseif (function_exists('mb_convert_encoding') && ($return = @mb_convert_encoding($data, $output, $input)))
{
return $return;
}
// This is last, as behaviour of this varies with OS userland and PHP version
elseif (function_exists('iconv') && ($return = @iconv($input, $output, $data)))
{
return $return;
}
// If we can't do anything, just fail
else
{
return false;
}
}
示例6: change_encoding
function change_encoding($data, $input, $output)
{
$input = SimplePie_Misc::encoding($input);
$output = SimplePie_Misc::encoding($output);
if ($input != $output) {
if (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], "{$output['encoding']}//TRANSLIT", $data)) {
return iconv($input['encoding'], "{$output['encoding']}//TRANSLIT", $data);
} else {
if (function_exists('iconv') && $input['use_iconv'] && $output['use_iconv'] && iconv($input['encoding'], $output['encoding'], $data)) {
return iconv($input['encoding'], $output['encoding'], $data);
} else {
if (function_exists('mb_convert_encoding') && $input['use_mbstring'] && $output['use_mbstring']) {
return mb_convert_encoding($data, $output['encoding'], $input['encoding']);
} else {
if ($input['encoding'] == 'ISO-8859-1' && $output['encoding'] == 'UTF-8') {
return utf8_encode($data);
} else {
if ($input['encoding'] == 'UTF-8' && $output['encoding'] == 'ISO-8859-1') {
return utf8_decode($data);
}
}
}
}
}
}
return $data;
}
示例7: change_encoding
function change_encoding($data, $input, $output)
{
$input = SimplePie_Misc::encoding($input);
$output = SimplePie_Misc::encoding($output);
if (function_exists('iconv') && ($return = @iconv($input, "{$output}//IGNORE", $data))) {
return $return;
} elseif (function_exists('iconv') && ($return = @iconv($input, $output, $data))) {
return $return;
} elseif (function_exists('mb_convert_encoding') && ($return = @mb_convert_encoding($data, $output, $input))) {
return $return;
} elseif ($input == 'ISO-8859-1' && $output == 'UTF-8') {
return utf8_encode($data);
} elseif ($input == 'UTF-8' && $output == 'ISO-8859-1') {
return utf8_decode($data);
}
return $data;
}