Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml_parse question

Status
Not open for further replies.

stasJohn

Programmer
May 6, 2004
155
US
php 4.3.11

I'm reading an rss feed and listing the items on my homepage.

I'm using Pears XML_Parser class

If a feed item has an apostrophe in it, it is converted to a question mark.

So,
Code:
<item>
  <title>Lot's of fun</title>
  ...
</item>
is printed out as "Lot?s of fun"

Here's my code
Code:
$rss =& new XML_RSS("[URL unfurl="true"]http://site.com/feed/");[/URL]
$rss->parse();
$headlines = $rss->getItems();

Now, if I stick an echo after $rss->parse() I can see all the apostrophes converted to question marks. I believe parse() actually uses xml_parse().

Is this a bug? Any ideas why it'd be doing that to the apostrophes?
 
Is there some other method I can use that would definetly work?
 
You can try using the miniXML package <
Here's some code that uses it to convert the returned XML string to an array.
Code:
<?
   include('./minixml.inc.php');
   $nf = '[URL unfurl="true"]http://site.com/feed/';[/URL]
   $xmlDoc = new MiniXMLDoc();
   $gm = fopen($nf,'r');
   $tmp = @fread($gm,30000);
   fclose($gm);
   $xmlDoc->fromString($tmp);
   $tmpa = $xmlDoc->toArray();
   echo '<pre>';print_r($tmpa);echo '</pre>';
?>
Look at the returned array and see if it suits your needs.

Ken
 
I'm figured out the problem, well sort of.

It seems that php was not properly detecting the character set of the feed. Which seems odd because UTF-8 is in the xml prolog and everything else I work on is in utf-8. Anywho, I manually set the encoding type to utf-8 and the apostrophes now appear as they should.

So, would this be a php bug? Any ideas? Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top