By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,831 Members | 2,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,831 IT Pros & Developers. It's quick & easy.

Encode German characters in XML

P: 69
Hi,

I'm doing some work for a German website. They want to be able to type in characters for which there are HTML entities like
Expand|Select|Wrap|Line Numbers
  1. Ü ü ä
. The plain text should be stored in a database so it can be later retrieved and read into an XML file. The XML file is read by a Flash file to create a news ticker.

Unfortunately the ticker is displaying some characters incorrectly. I thought that you would need to use html_entities when writing to the database, html_entity_decode when reading from it and the ISO encoding in the XML file. Could anyone tell me where I'm going wrong.

Expand|Select|Wrap|Line Numbers
  1.  
  2. // Writing to the database.
  3.  
  4. $sql = "UPDATE news SET title = " . '"' . htmlentities( addslashes($_POST['title']), ENT_QUOTES, 'ISO-8859-1' ) . '"' . ", article = " . '"' . 
  5.         addslashes($_POST['article']) . '"' . ", summary = " . '"' . addslashes($_POST['summary']) . '"';
  6.     if(isset($filename1)) $sql .= ", image_file = '$filename1' ";
  7.     $sql .= "WHERE news_id = {$_POST['articleId']}";
  8.  
  9. // Reading from the database.
  10. $sql = "SELECT * FROM news ORDER BY news_id DESC";
  11.     $result = $con->sqlExecute($sql);
  12.  
  13.     $xmlContent = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
  14.     $xmlContent .= "<ticker>\n";
  15.  
  16.     while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
  17.         $xmlContent .= "<topic>\n";
  18.         $xmlContent .= "<text><![CDATA[<font size=\"12px\" color=\"#624A9E\"><b>" . html_entity_decode( $row['title'], ENT_QUOTES, 'ISO-8859-1' ) . "</b></font><br /><font size=\"12px\" color=\"#686868\">$row['summary'] )...</font><br /><font size=\"12px\" color=\"#624A9E\"><b>Read more</b></font>]]></text>\n";
  19.         $xmlContent .= "<link>NewsDetail.php?news_id={$row['news_id']}</link>\n";
  20.         $xmlContent .= "<targetIsUrl>Y</targetIsUrl>\n";
  21.         $xmlContent .= "</topic>";
  22.     }
  23.  
  24. // First line of XML.
  25. <?xml version="1.0" encoding="ISO-8859-1"?>
  26.  
  27.  
Thanks,

Sean
Feb 14 '08 #1
Share this Question
Share on Google+
1 Reply


MarkoKlacar
Expert 100+
P: 296
Hi Sean,

I've done a simliar thing but with swedish characters, , I did not do any of the things you are talking about and it worked out fine, the PHP bit.

Maybe the flash is doing something nasty to the characters.
Feb 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.