質問箱/3378
の編集
Top
/
質問箱
/
3378
[
トップ
] [
編集
|
差分
|
履歴
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
Wikiを試したい方へ:
「この」Wikiは、
PukiWiki
のための公式Wikiです。
テスト書き込みなどは
お試しサイト
https://pukiwiki.osdn.jp/_trial/
をご利用ください
**[[質問箱/3378]] [#m518dc1d] |RIGHT:100|LEFT:410|c |~カテゴリ|| |~サマリ|#showrss の不具合??| |~バージョン|1.4.6| |~投稿者|[[matsuo2]]| |~状態|完了| |~投稿日|&new{2006-04-06 (木) 01:19:31};| ***質問 [#s2b1d7ff] 天気予報を表示しようとしたのですが ◆天気 愛知 西部(名古屋) #showrss(http://weather.goo.ne.jp/area/5110.rdf,0,1) ↑表示されない。(06/04/06) ◆天気 愛知 東部(豊橋) #showrss(http://weather.goo.ne.jp/area/5120.rdf,0,1) ↑こちらはうまく表示される。 他のrssリーダではうまく表示されていたので#showrssに原因があるのではないかと・・・ ***回答 [#f75079e5] - mb_detect_encoding() が EUCのところをUTF-8と誤検出するのが原因でした。判定部分に手を入れてみました。 -- [[matsuo2]] &new{2006-04-16 (日) 19:43:15}; --- showrss.inc.php.org +++ showrss.inc.php @@ -52,9 +51,13 @@ if (! class_exists($class)) $class = 'ShowRSS_html'; list($rss, $time) = plugin_showrss_get_rss($rssurl, $usecache); + if ($rss === FALSE) return '<p>showrss: cannot get rss from server.</p>' . "\n"; + if (is_string($rss)) + return "<p>showrss: error ${rss}\n"; + $obj = new $class($rss); $timestamp = ''; @@ -210,12 +213,20 @@ $this->is_item = FALSE; $this->tag = ''; - // Detect encoding - $this->encoding = mb_detect_encoding($buf); + /* Detect encoding ex. <?xml version="1.0" encoding="EUC-JP" ?> */ + $lines = split(">", $buf, 1); + if (preg_match( "/encoding=\"(.+)\"/i", $lines[0], $encoding)) { + $this->encoding = $encoding[1]; + } else { + $this->encoding = mb_detect_encoding($buf); + } + + // Convert to utf-8 if (! in_array(strtolower($this->encoding), array('us-ascii', 'iso-8859-1', 'utf-8'))) { $buf = mb_convert_encoding($buf, 'utf-8', $this->encoding); $this->encoding = 'utf-8'; } + $xml_parser = xml_parser_create($this->encoding); xml_set_element_handler($xml_parser, array(& $this, 'start_element'), array(& $this, 'end_element')); xml_set_character_data_handler($xml_parser, array(& $this, 'character_data')); - [[dev:BugTrack2/176]] -- &new{2006-04-30 (日) 22:38:28}; #comment
**[[質問箱/3378]] [#m518dc1d] |RIGHT:100|LEFT:410|c |~カテゴリ|| |~サマリ|#showrss の不具合??| |~バージョン|1.4.6| |~投稿者|[[matsuo2]]| |~状態|完了| |~投稿日|&new{2006-04-06 (木) 01:19:31};| ***質問 [#s2b1d7ff] 天気予報を表示しようとしたのですが ◆天気 愛知 西部(名古屋) #showrss(http://weather.goo.ne.jp/area/5110.rdf,0,1) ↑表示されない。(06/04/06) ◆天気 愛知 東部(豊橋) #showrss(http://weather.goo.ne.jp/area/5120.rdf,0,1) ↑こちらはうまく表示される。 他のrssリーダではうまく表示されていたので#showrssに原因があるのではないかと・・・ ***回答 [#f75079e5] - mb_detect_encoding() が EUCのところをUTF-8と誤検出するのが原因でした。判定部分に手を入れてみました。 -- [[matsuo2]] &new{2006-04-16 (日) 19:43:15}; --- showrss.inc.php.org +++ showrss.inc.php @@ -52,9 +51,13 @@ if (! class_exists($class)) $class = 'ShowRSS_html'; list($rss, $time) = plugin_showrss_get_rss($rssurl, $usecache); + if ($rss === FALSE) return '<p>showrss: cannot get rss from server.</p>' . "\n"; + if (is_string($rss)) + return "<p>showrss: error ${rss}\n"; + $obj = new $class($rss); $timestamp = ''; @@ -210,12 +213,20 @@ $this->is_item = FALSE; $this->tag = ''; - // Detect encoding - $this->encoding = mb_detect_encoding($buf); + /* Detect encoding ex. <?xml version="1.0" encoding="EUC-JP" ?> */ + $lines = split(">", $buf, 1); + if (preg_match( "/encoding=\"(.+)\"/i", $lines[0], $encoding)) { + $this->encoding = $encoding[1]; + } else { + $this->encoding = mb_detect_encoding($buf); + } + + // Convert to utf-8 if (! in_array(strtolower($this->encoding), array('us-ascii', 'iso-8859-1', 'utf-8'))) { $buf = mb_convert_encoding($buf, 'utf-8', $this->encoding); $this->encoding = 'utf-8'; } + $xml_parser = xml_parser_create($this->encoding); xml_set_element_handler($xml_parser, array(& $this, 'start_element'), array(& $this, 'end_element')); xml_set_character_data_handler($xml_parser, array(& $this, 'character_data')); - [[dev:BugTrack2/176]] -- &new{2006-04-30 (日) 22:38:28}; #comment
テキスト整形のルールを表示する