Encode German characters in XML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sebarry
    New Member
    • Jul 2007
    • 69

    Encode German characters in XML

    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
    Code:
    Ü ü ä
    . 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_dec ode when reading from it and the ISO encoding in the XML file. Could anyone tell me where I'm going wrong.

    Code:
    // Writing to the database.
    
    $sql = "UPDATE news SET title = " . '"' . htmlentities( addslashes($_POST['title']), ENT_QUOTES, 'ISO-8859-1' ) . '"' . ", article = " . '"' . 
    		addslashes($_POST['article']) . '"' . ", summary = " . '"' . addslashes($_POST['summary']) . '"';
    	if(isset($filename1)) $sql .= ", image_file = '$filename1' ";
    	$sql .= "WHERE news_id = {$_POST['articleId']}";
    
    // Reading from the database.
    $sql = "SELECT * FROM news ORDER BY news_id DESC";
    	$result = $con->sqlExecute($sql);
    
    	$xmlContent = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
    	$xmlContent .= "<ticker>\n";
    	
    	while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
    		$xmlContent .= "<topic>\n";
    		$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";
    		$xmlContent .= "<link>NewsDetail.php?news_id={$row['news_id']}</link>\n";
    		$xmlContent .= "<targetIsUrl>Y</targetIsUrl>\n";
    		$xmlContent .= "</topic>";
    	}
    
    // First line of XML.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    Thanks,

    Sean
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    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.

    Comment

    Working...