PHP解析)クラスのシンプルモデル_同前domのトランスコードbug
2660 ワード
ここ数日はシンプルなものを使っています。同前domはいくつか文章をつかんでいます。異なるサイトのコードは国内では基本的にgbk gb 2312 utf-8です。gb 2312とutf-8が多いです。
私のこのバージョンのsimple_同前domには一つの方法があります。textはこのようです。
私のこのバージョンのsimple_同前domには一つの方法があります。textはこのようです。
// PaperG - Function to convert the text from one character set to another if the two sets are not the same.
function convert_text($text)
{
global $debug_object;
if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}
$converted_text = $text;
$sourceCharset = "";
$targetCharset = "";
if ($this->dom)
{
$sourceCharset = strtoupper($this->dom->_charset);
$targetCharset = strtoupper($this->dom->_target_charset);
}
if (is_object($debug_object)) {$debug_object->debug_log(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);}
if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0))
{
// Check if the reported encoding could have been incorrect and the text is actually already UTF-8
if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text)))
{
$converted_text = $text;
}
else
{
$converted_text = iconv($sourceCharset, $targetCharset, $text);
}
}
// Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output.
if ($targetCharset == 'UTF-8')
{
if (substr($converted_text, 0, 3) == "\xef\xbb\xbf")
{
$converted_text = substr($converted_text, 3);
}
if (substr($converted_text, -3) == "\xef\xbb\xbf")
{
$converted_text = substr($converted_text, 0, -3);
}
}
return $converted_text;
}
この行を見に来ました
$converted_text = iconv($sourceCharset, $targetCharset, $text);
トランスコードが正しくないことを引き起こします。例えばgb 2312の文字を変換します。
4 26 <span style="color:#C03"></span> 2014 ,24 ... 7 <span style="color:#C03"> </span> , 77 07 ...
既成の事実は、中のトランスコード機能がうまく処理されていないことを証明します。私はこのシンプルを使っていますので。同前domはdomを構築するために使うだけです。このバグを時間をかけて上手く処理するつもりはありません。簡単に
$converted_text = iconv($sourceCharset, $targetCharset, $text);
せいにする
$converted_text = $text;
いいです。考え方はそのトランスコードをキャンセルすることです。いいです。仕事は気にする必要はありません。続けてもいいです。