views:

38

answers:

5

I have a webpage that is set to UTF-8. But parts of its content (built in php) come from iso-8859-1 files and are thus not displayed correctly.

Is it possible to set a specific encoding for a particular page element?

A: 

No, I don't think this can be done. Since you already use UTF-8 inside the page, there must be something wrong while reading the content from other pages if you get unexpected results. You shouldn't experience any problems with a UTF-8 page.

Vasileios Lourdas
A: 

No, only a single encoding can be used on one page. You might want to encode your iso-stuff to entities that's generated by PHP.

TuomasR
I can't, these files are also used by an other website where everything is encoded in ISO
tool
A: 

You may end up using an iframe to display the other content so you can set your meta tag for the character encoding you need.

shady
I'd rather not, but thanks for the idea
tool
A: 

How are you inserting the Latin-1 files into the page? If you're loading them as text and then including them as text, then I'd hope the relevant conversion would be performed for you. If you're just including the files without any transformation, that would indeed be an issue.

I don't know what PHP uses as its internal text format (e.g. Unicode) but if you can use that as an intermediate encoding, it should be okay.

Jon Skeet
PHP loads the content of the file (a list of items). I could use php to change encoding on the fly. But I hoped that I could just add an attribute to the div.
tool
@tool: I don't believe so... it would be pretty odd, really. Bear in mind that the HTTP response has already specified the content type, optionally including encoding.
Jon Skeet
Yeah, but the thing is I remember reading somewhere that it was possible, but I can't find the article. O maybe I'm just mistaken...
tool
+1  A: 

You could, instead of including that output directly, pass that php output through a conversion script.

PhP has a decent conversion function mb_convert_encoding that could make the task easier.

aeon
+1 this is the way to go. `mb_convert_encoding()` or `iconv()` will sort out all the troubles for you.
Pekka
I'll do that, thanks
tool