You are here:  » Character encoding


Character encoding

Submitted by waltonp on Wed, 2006-10-25 10:14 in

Hi

I'm using magic parser to manipulate the xml supplied by OMG to create pages for my website here:
http://www.car-insurance-uk-quote.com/Barclays-Car-Insurance/index.html
for example.

The only problem I have is there are characters that can't be translated properly and come out a question marks.

If you put the feed url
e.g.http://creatives.omg2.com/GetEditorial.asp?type=xml&EditorialID=1355&MID=2020&PID=2187&AID=1235&CID=57793&WID=4115
into the magicparser.com/demo form it comes out ok. I've tried all sorts of encoding in the meta tags field but the result is the same.

The php I'm using is similar to this:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  
MagicParser_parse("http://creatives.omg2.com/GetEditorial.asp?Type=xml&EditorialID=1355&MID=2020&PID=2187&AID=1235&CID=57793&WID=4115","myRecordHandler","xml|ROOT/");
?>

Can you see anything obvious I'm missing.

Thanks

Submitted by support on Wed, 2006-10-25 11:03

Hi,

Which editorial ID is the one producing the question marks?

The link you provided shows a short Barclays paragraph which appears OK on your site site, but I can't find the XML source of the one creating the encoding errors.

What source XML would provide that one...

Cheers,
David.

Submitted by waltonp on Wed, 2006-10-25 12:19

All of the pages using omg feeds have this error. An example is:
http://www.car-insurance-uk-quote.com/Barclays-Car-Insurance/index.html

which uses this xml feed http://creatives.omg2.com/GetEditorial.asp?Type=xml&EditorialID=1346&MID=2020&PID=2187&AID=1235&CID=57793&WID=4115
(I gave you the wrong one). I can see now that it's translating • into ?'s.

Submitted by support on Wed, 2006-10-25 12:41

Hi,

The feed seems to be UTF-16 encoded, but the contents display OK under the UTF-8 character set; so you can force this with a header() statement in your script. Here's my test script:

Output

Source:

<?php
  header
("Content-Type: text/html; charset=utf-8");
  require(
"MagicParser.php");
  function 
myRecordHandler($record)
  {
    print 
$record["DBO.MERCHANTEDITORIAL-EDITORIAL"];
  }
  
MagicParser_parse("http://creatives.omg2.com/GetEditorial.asp?Type=xml&EditorialID=1346&MID=2020&PID=2187&AID=1235&CID=57793&WID=4115","myRecordHandler","xml|ROOT/");
?>

If you just add the header() statement from the above code to your script you should find it works ok...

Cheers,
David.

Submitted by waltonp on Wed, 2006-10-25 13:08

Hi

I've tried that. Because i'm inserting the php script into an html file it doesn't like the header statement and will not execute.

Submitted by support on Wed, 2006-10-25 13:13

Do you have any control over the higher level HTML document. Ideally you would need to be able to insert it at the top (header statements must go before any output has been generated) - so what you would need to use is:

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

Are you not able to do that?

Cheers,
David.

Submitted by waltonp on Wed, 2006-10-25 13:19

No. I didn't do that. I put it with the rest of the php code where the statements are for magic parser. Not thinking straight. Isn't it the same as putting in a meta tag though or does it work in a different way? I'll give it a go.