XMLファイルを解析しようとしましたが、ファイルにアクセント(é、à、...)があると、php xmlパーサーが文字列を切り捨てます。アクセントを含むXMLパーサーカット文字列
function __construct(){
$this->xml_parser = xml_parser_create("UTF-8");
xml_set_object ( $this->xml_parser, $this);
xml_set_element_handler($this->xml_parser, "startTagArticle", "endTagArticle");
xml_set_character_data_handler($this->xml_parser, "contentsArticle");
}
私のファイルは、以下の文字列が含まれている場合:cccccékkkkkkéllllllllを、それは私のWebブラウザでékkkkkélllllllとして表示されます、と私は理由を知りません。
<?xml version="1.0" encoding="utf-8"?>
<XML>
<TITRE>cccccékkkkkkéllllllll</TITRE>
<RESUME>Ceci est le premieré article de blog et l'aut</RESUME>
<CONTENT>Ceci l'aut est effectivement mon premier article de blog
et c'est un test
</CONTENT>
<FILE_COMMENTS>com1.xml</FILE_COMMENTS>
<VISIBLE>true</VISIBLE>
<TAG>Cool</TAG>
<TAG>article</TAG>
</XML>
基本的な解析機能:。私はで=を交換した次contentsArticle機能を使用する場合
function startTagArticle($parser, $data){ switch ($data){ case "RESUME":
$this->articleSection = 1;
break; case "CONTENT":
$this->articleSection = 2;
break; case "FILE_COMMENTS":
$this->articleSection = 3;
break; case "VISIBLE":
$this->articleSection = 4;
break; case "TITRE":
$this->articleSection = 5;
break; case "TAG":
$this->articleSection = 6;
break; default:
$this->articleSection = 0;
break; } }
/** Do not work **/
function contentsArticle($parser, $data){
if ($this->articleSection == 1){
$this->resumeArticleCourant = $data;
}
if ($this->articleSection == 2){
$this->contentArticleCourrant = $data;
}
if ($this->articleSection == 3){
$this->fichier_comArticleCourant = $data;
$this->comm = new commentaire();
$this->comm->init($this->comm_rep.$data);
}
if ($this->articleSection == 4){
$this->visibleArticleCourant = $data;
}
if ($this->articleSection == 5){
$this->titreArticleCourant = $data;
}
if ($this->articleSection == 6){
array_push($this->tag_array,$data);
}
}
奇妙なことがある=、それが正常に動作します。アクセント文字はXMLフローをカット/ストップさせるようです。
/** work **/
function contentsArticle($parser, $data){
if ($this->articleSection == 1){
$this->resumeArticleCourant .= $data;
}
if ($this->articleSection == 2){
$this->contentArticleCourrant .= $data;
}
if ($this->articleSection == 3){
$this->fichier_comArticleCourant = $data;
$this->comm = new commentaire();
$this->comm->init($this->comm_rep.$data);
}
if ($this->articleSection == 4){
$this->visibleArticleCourant = $data;
}
}
if ($this->articleSection == 5){
$this->titreArticleCourant .= $data;
}
if ($this->articleSection == 6){
array_push($this->tag_array,$data);
}
}
を役に立てば幸い? 例:header( "Content-Type:text/xml; charset = utf-8");ブラウザで「ソースを表示」すると、完全な文字列または切り取られた文字列が表示されますか?あなたが切り取ったものを見ると、問題は解析中です。さもなければ、おそらく符号化の問題です。 – Yaniro
XMLファイルをブラウザで直接開くと、完全な文字列が表示されます。だから、解析の問題が多いと思います。 – psic
同じ振る舞いで、同じ診断で解決されました。私は '='を '。='に変更し、単語は分割されません。とにかくなぜか分からない。 – Sebastian