Jump to content

Strange Characters not Decoding Correctly


dbol

Recommended Posts

I cannot seem to parse special characters correctly. I tried passing it through a converter (iconv) to encode in UTF-8, but it doesn't help.

 

My XML file is as follows:

<rss version="2.0">
<channel>
	<item> 
		<title>Email: Deval Patrick premium caps could cause &#38;#x2018;train wreck&#38;#x2019; - BostonHerald.com</title> 
		<link>http://news.bostonherald.com/business/healthcare/view/20100608email_deval_patrick_premium_caps_could_cause_train_wreck/srvc=home&#38;#x26;amp;position=recent</link> 
		<description>BOSTON &#38;#x2014; A top state insurance official said that health insurance caps the Patrick administration placed on major insurers could cripple them financially and would most likely cause &#38;#x22;a train wreck,&#38;#x22; according to an email obtained Tuesday by The Associated...</description> 
		<pubDate>Tue, 08 Jun 2010 20:56:52 GMT</pubDate> 
		<source url="http://news.bostonherald.com/">BostonHerald.com</source> 
	</item>
</channel>
</rss>

 

My PHP is as follows:

<?php 

$incoming = file_get_contents("parsexml.xml");
$simplexml= iconv( "UTF-8", "ISO-8859-1//TRANSLIT", $incoming);
$simplexml = simplexml_load_string($simplexml);
$items = $simplexml->channel->item;

?> 

<html> 
<head> 
<title>Parse Special Chars</title> 
</head>
<body bgcolor="#FFFFFF">
<center><h1>Title</h1></center>
<br/>
<table align="center">
<tr>
<td width="600">
<?php
foreach ($items as $item){
echo "<b>" . $item->title . "</b><br/>";
}
?>
</tr>
</td>
</tr>
</table>

</body> 
</html>

 

Notice the title has odd characters around 'train wreck' where there should be apostrophes.

 

I've also attached both the xml and php file for convenience.

 

 

Thanks.

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.