Я генерирую много постов в Wordpress из файла XML.Беспокойство: акцентированные символы.
Заголовок потока:
<? Xml version = "1.0" encoding = "ISO-8859-15"?>
Вот полный поток: http://flux.netaffiliation.com/rsscp.php?maff=177053821BA2E13E910D54
Мой сайт находится в utf8.
Поэтому я использую функцию utf8_encode ... но это не решает проблему, акценты всегда неправильно понимаются.
У кого-нибудь есть идея?
РЕДАКТИРОВАТЬ04-10-2011 18:02 (французский час):
Вот полный поток: http://flux.netaffiliation.com/rsscp.php?maff=177053821BA2E13E910D54
Вот мой код:
/**
* parse an rss flux from netaffiliation and convert each item to posts
* @var $flux = external link
* @return bool
*/
private function parseFluxNetAffiliation($flux)
{
$content = file_get_contents($flux);
$content = iconv("iso-8859-15", "utf-8", $content);
$xml = new DOMDocument;
$xml->loadXML($content);
//get the first link : http://www.netaffiliation.com
$link = $xml->getElementsByTagName('link')->item(0);
//echo $link->textContent;
//we get all items and create a multidimentionnal array
$items = $xml->getElementsByTagName('item');
$offers = array();
//we walk items
foreach($items as $item)
{
$childs = $item->childNodes;
//we walk childs
foreach($childs as $child)
{
$offers[$child->nodeName][] = $child->nodeValue;
}
}
unset($offers['#text']);
//we create one article foreach offer
$nbrPosts = count($offers['title']);
if($nbrPosts <= 0)
{
echo self::getFeedback("Le flux ne continent aucune offre",'error');
return false;
}
$i = 0;
while($i < $nbrPosts)
{
// Create post object
$description = '<p>'.$offers['description'][$i].'</p><p><a href="'.$offers['link'][$i].'" target="_blank">'.$offers['link'][$i].'</a></p>';
$my_post = array(
'post_title' => $offers['title'][$i],
'post_content' => $description,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(self::getCatAffiliation())
);
// Insert the post into the database
if(!wp_insert_post($my_post));;
$i++;
}
echo self::getFeedback("Le flux a généré {$nbrPosts} article(s) depuis le flux NetAffiliation dans la catégorie affiliation",'updated');
return false;
}
Все сообщения созданы, но ... акцентированные символы уродливы.Вы можете увидеть результат здесь: http://monsieur -mode.com / test /