Я пытаюсь разобрать файл XML, но когда в моем файле есть ударение (é, à, ...), синтаксический анализатор php 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, он будет отображаться как é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>
Основная функция разбора:
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);
}
}
Странная вещь, если я использую следующую функцию contentArticle, где я заменил = на. =, Она работает нормально. Символы ударений, кажется, обрезают / останавливают поток 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);
}
}