Jump to content

SimpleXML and htmlspecialchars?


digitus78

Recommended Posts

Hello and thanks in advance for any help.

 

Overview:

Im tyring to pull data from a XML api using simpleXML.  I have ran into a problem with special characters and entities that simpleXML does not accept.

IE " "  Ive tried all the solutions i could find to no avail.

 

SimpleXML gives me this error.

 

parser error : Entity 'nbsp' not defined in

 

Here is my code.

 

$feed = simplexml_load_file('URL TO API FEED');
$feed = html_entity_decode($feed);
$feed = str_ireplace(array('<','>','&','\'','"'),array('<','>','&',''','"'),$feed);

echo 'Game Title: ' .$feed->game. '</br>';
echo 'Ponts Earned: ' .$feed->gamerscore. '</br>';
echo 'Total Achievements: ' .$feed->totalachievements. '</br>';

foreach($feed->achievements->achievement as $ach) {

$output = htmlentities($feed->title, ENT_QUOTES, "UTF-8");
echo $output;
if( !empty($ach->unlockedartwork)){
echo '<img src=' .$ach->unlockedartwork. '></img></br>';
}else {
echo '<img src=' .$ach->artwork. '></img></br>';
}

}

 

Here is the code im trying to retrieve.

      <achievement id="40">
          <title>Have Gun Will Travel </title>
          <artwork>http://</artwork>
          <gamerscore>20</gamerscore>
          <unlocked>true</unlocked>
          <unlockdate>7/4/2010</unlockdate>
      </achievement>

Link to comment
https://forums.phpfreaks.com/topic/246141-simplexml-and-htmlspecialchars/
Share on other sites

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.