Jump to content

simplexml and non-standard characters


maddogandnoriko

Recommended Posts

I have an xml file loaded into a simplexml object. The xml has a "ö" in it and is getting garbled in the simplexml object. Here is my test code:

 

<?php 
      $seriesURL='http://www.thetvdb.com/api/GetSeries.php?seriesname=krod';
      echo 'SeriesURL:'.$seriesURL.'<br><br>';
      $data = simplexml_load_file($seriesURL);
      
      echo '<br><br>'. ($data->Series->SeriesName);
?>

 

The resulting Series Name is: Kröd Mändoon and the Flaming Sword of Fire

 

Link to comment
Share on other sites

http://www.thetvdb.com/api/GetSeries.php?seriesname=krod seem a valid utf-8 xml file.

 

Try that at the begining of your php :

 

<?php
header('Content-Type: text/html; charset=utf-8');
...
?>

 

And in your output html :

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>

...

</body>
</html>

 

It tell the browser (or whatever client) that your output is encoded in utf-8. Because the content in the xml is encoded in utf-8 (like it should).

 

Or you can convert your data into ASCII html entities and it will work no matter what encoding you use with htmlentities() like that :

 

<?php
...
$output = htmlentities($data->Series->SeriesName, ENT_QUOTES, "UTF-8");
echo $output;
...
?>

Don't encode the whole XML, only the data part.

 

http://www.php.net/manual/en/function.htmlentities.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.