Add support for encoding option
git-svn-id: http://php-reader.googlecode.com/svn/trunk@129 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
@@ -195,7 +195,7 @@ abstract class ID3_Object
|
||||
/**
|
||||
* Reverses the unsynchronisation scheme from the given data string.
|
||||
*
|
||||
* @see encodeUnsyncronisation
|
||||
* @see encodeUnsynchronisation
|
||||
* @param string $data The input data.
|
||||
* @return string
|
||||
*/
|
||||
@@ -248,4 +248,42 @@ abstract class ID3_Object
|
||||
{
|
||||
return preg_split("/\\x00/", $value, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts string to requested character encoding and returns it. See the
|
||||
* documentation of iconv for accepted values for encoding.
|
||||
*
|
||||
* @param string|Array $string
|
||||
* @param string $encoding
|
||||
*/
|
||||
protected function convertString($string, $encoding)
|
||||
{
|
||||
$target = $this->getOption("encoding", ID3_Encoding::UTF8);
|
||||
switch ($target) {
|
||||
case ID3_Encoding::UTF16:
|
||||
$target = "utf-16";
|
||||
break;
|
||||
case ID3_Encoding::UTF16LE:
|
||||
$target = "utf-16le";
|
||||
break;
|
||||
case ID3_Encoding::UTF16BE:
|
||||
$target = "utf-16be";
|
||||
break;
|
||||
case ID3_Encoding::UTF8:
|
||||
$target = "utf-8";
|
||||
break;
|
||||
default:
|
||||
$target = "iso-8859-1";
|
||||
}
|
||||
|
||||
if (strtolower($target) == strtolower($encoding))
|
||||
return $string;
|
||||
|
||||
if (is_array($string))
|
||||
foreach ($string as $key => $value)
|
||||
$string[$key] = iconv($encoding, $target, $value);
|
||||
else
|
||||
$string = iconv($encoding, $target, $string);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user