utf 8 - XML is not read correctly (ISO-8859-1 / UTF-8) -


i have little piece of code, reading easy affiliate xml. url http://pf.tradetracker.net/?aid=193104&encoding=iso-8859-1&type=xml-v2&fid=556821&r=tt-canvasholidays.nl&categorytype=2&additionaltype=2

when try put xml in array , process basic functions, seems special characters being replaced encoded ones.

for example word château in original xml replaced château when read xml in php follows:

$xml = simplexml_load_file($file); foreach($xml->product $child) {   $name = mysql_real_escape_string($child->name);   } 

had programmed escape function replaces of Ãx-things correct characters, "â" string seems not accepted in php code.

i have read articles wrong database conversion, i'm reading , interpreting source xml , in simplexml_load_file no encoding specified.

o btw, i'm not experienced php programmer, stuck wordpress in combination proven technologies affiliate productfeeds, until french data coming through :)

hope can help... in advance...

as know, xml document in iso-8859-1 encoding. suspect you're outputting $name utf-8 encoded page (although doesn't explain conversion of château château).

once you've resolved character encoding issue, shouldn't need replace characters or try fix them.

you can try 1 of following (3 best):

  1. set output encoding iso-8859-1
  2. convert input xml utf-8 iconv
  3. request xml document in utf-8: http://pf.tradetracker.net/?aid=193104&encoding=utf-8&type=xml-v2&fid=556821&r=tt-canvasholidays.nl&categorytype=2&additionaltype=2

if you're still having problems, suspect source document being downloaded incorrectly.

the following code works fine me (using http://phphttpclient.com/downloads/httpful.phar):

<?php include('./httpful.phar');  $xml_string = \httpful\request::get('http://pf.tradetracker.net/?aid=193104&encoding=utf-8&type=xml-v2&fid=556821&r=tt-canvasholidays.nl&categorytype=2&additionaltype=2')->send(); $xml = simplexml_load_string($xml_string);  header('content-type: text/html; charset=utf-8');  foreach($xml->product $child) {     echo $child->name . "<br>"; } 

?>

update: seems simplexml convert output utf-8 automatically, presumably based on encoding declaration of xml.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -