title: Make a working xml file in php (encoding properly) to export data from online database to iphone
body: <p>I am trying to make an xml file to export my data from my database to my iphone. Each time I create a new post, I need to execute a php file to create a xml file containing the latest post ;)</p>
  
  <p>Okay so far ? :D</p>
  
  <p>Here is current php code ... but my nsxmlparser gives me an error code (33 - String is not started). I have no idea what kind of php functions I have to use ...</p>
  
  <pre><code>&lt;?php
  
  // Èdition du dÈbut du fichier XML
  $xml .= '&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;';
  $sml .= '&lt;channel&gt;'; 
  $xml .= '&lt;title&gt;Infonul&lt;/title&gt;';
  $xml .= '&lt;link&gt;aaa&lt;/link&gt;';
  $xml .= '&lt;description&gt;aaa&lt;/description&gt;';
  
  
  // connexion a la base (mettre ‡ jour le mdp)
  $connect = mysql_connect('...-12','...','...');
  
  
  /* selection de la base de donnÈe mysql */
  mysql_select_db('...');
  
  
  // selection des 20 derniËres news
  $res=mysql_query("SELECT u.display_name as author,p.post_date as date,p.comment_count as commentCount, p.post_content as content,p.post_title as title FROM wp_posts p, wp_users u WHERE p.post_status = 'publish' and p.post_type = 'post' and p.post_author = u.id ORDER BY p.id DESC LIMIT 0,20");
  
  
  
  
  // extraction des informations et ajout au contenu
  while($tab=mysql_fetch_array($res)){   
  
   $title=$tab[title];
   $author=$tab[author];
   $content=$tab[content]; //html stuff
   $commentCount=$tab[commentCount];
   $date=$tab[date];
  
   $xml .= '&lt;item&gt;';
   $xml .= '&lt;title&gt;'.$title.'&lt;/title&gt;';
   $xml .= '&lt;content&gt;&lt;![CDATA['.$content.']]&gt;&lt;/content&gt;';
   $xml .= '&lt;date&gt;'.$date.'&lt;/date&gt;';
   $xml .= '&lt;author&gt;'.$author.'&lt;/author&gt;';
   $xml .= '&lt;commentCount&gt;'.$commentCount.'&lt;/commentCount&gt;';
   $xml .= '&lt;/item&gt;'; 
  }
  
  // Èdition de la fin du fichier XML
  $xml .= '&lt;/channel&gt;';
  $xml = utf8_encode($xml);
  
  echo $xml;
  
  // Ècriture dans le fichier
  if ($fp = fopen("20news.xml",'w'))
  {
   fputs($fp,$xml);
   fclose($fp);
  }
  
  //mysql_close();
  
  ?&gt;
  </code></pre>
  
  <p>I noticed a few things when i open 20news.xml in my browser :</p>
  
  <ul>
  <li>I got squares instead of single quotes ...</li>
  <li>I can't see &lt;[CDATA[ but ]]> is clearly visible ... why ?!?</li>
  </ul>
  
  <p>Thanks for any input ;)</p>
  
  <p>Gotye.</p>