title: parsing xml and output encoding in php
body: <p>I generate a lot of posts in Wordpress from an XML file. The worry: accented characters.</p>
  
  <p>The header of the stream is: </p>
  
  <pre><code>&lt;? Xml version = "1.0" encoding = "ISO-8859-15"?&gt;
  </code></pre>
  
  <p>Here is the complete flux : <a href="http://flux.netaffiliation.com/rsscp.php?maff=177053821BA2E13E910D54" rel="nofollow">http://flux.netaffiliation.com/rsscp.php?maff=177053821BA2E13E910D54</a></p>
  
  <p>My site is in utf8.</p>
  
  <p>So I use the function utf8_encode ... but that does not solve the problem, the accents are always misunderstood.</p>
  
  <p>Does anyone have an idea?</p>
  
  <p><strong>EDIT 04-10-2011 18:02 (french hour) :</strong></p>
  
  <p>Here is the complete flux : <a href="http://flux.netaffiliation.com/rsscp.php?maff=177053821BA2E13E910D54" rel="nofollow">http://flux.netaffiliation.com/rsscp.php?maff=177053821BA2E13E910D54</a></p>
  
  <p>Here is my code :</p>
  
  <pre><code>/**
   * 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-&gt;loadXML($content);
  
      //get the first link : http://www.netaffiliation.com
      $link = $xml-&gt;getElementsByTagName('link')-&gt;item(0);
      //echo $link-&gt;textContent;
  
      //we get all items and create a multidimentionnal array
      $items = $xml-&gt;getElementsByTagName('item');
  
      $offers = array();
      //we walk items
      foreach($items as $item)
      {
          $childs = $item-&gt;childNodes;
  
          //we walk childs
          foreach($childs as $child)
          {
              $offers[$child-&gt;nodeName][] = $child-&gt;nodeValue;
          }
  
      }
      unset($offers['#text']);
  
      //we create one article foreach offer
      $nbrPosts = count($offers['title']);
  
      if($nbrPosts &lt;= 0) 
      {
          echo self::getFeedback("Le flux ne continent aucune offre",'error');
          return false;
      }
  
      $i = 0;
      while($i &lt; $nbrPosts)
      {
          // Create post object
          $description = '&lt;p&gt;'.$offers['description'][$i].'&lt;/p&gt;&lt;p&gt;&lt;a href="'.$offers['link'][$i].'" target="_blank"&gt;'.$offers['link'][$i].'&lt;/a&gt;&lt;/p&gt;';
  
          $my_post = array(
              'post_title' =&gt; $offers['title'][$i],
              'post_content' =&gt; $description,
              'post_status' =&gt; 'publish',
              'post_author' =&gt; 1,
              'post_category' =&gt; 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;
  
  }
  </code></pre>
  
  <p>All the posts are generated but... the accented chars are ugly. You can see the result here: <a href="http://monsieur-mode.com/test/" rel="nofollow">http://monsieur-mode.com/test/</a></p>