• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Getting charset of web page and setting output charset encoding.

Hi,
I'm looking for a solution to problem with getting and setting the character encoding.
The problem:
I have a code that outputs some text. This code is included in pages where I do not have the control over character encoding. My text comes from PHP as UTF-8 by default.

What I need is: get the character encoding of the "master" page and converting the "myscript" output text to the character set of the master page.

no mbstring extension available ...

Thanks
0
bitfactory
Asked:
bitfactory
  • 3
  • 3
1 Solution
 
bitfactoryAuthor Commented:
sorry I can't access that link...
0
 
The_Blasted_OneCommented:
You can check iconv extension instead of mbstring. It has the similar features. There are servers which have one of them unavailable and another one available, the substitution had saved me a few times.

Otherwise you will need the custom function that will do the same trick. But the function will depend on "in" and "out" encoding (utf7_to_utf8, etc).  There are many available on the web but none of them are universal AFAIK.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
The_Blasted_OneCommented:
BTW, if you need a simple ISO to UTF8 conversion, you may also try utf8_encode, if XML extension is available for you.

Sorry, that article is not a case, the performance will drop dead if your script will try to check for an encoding by fetching the page output.
You'll be better to determine the "master" encoding manually. Or if your provide an include for third parties, let them choose output encoding by providing your script a charset argument via GET or something like.
0
 
bitfactoryAuthor Commented:
Thanks for your comments. I have tried iconv before I posted here, but couldn't find the possibility to get the master web site charset ... Anyway, I have been thinking a lot about this and in fact there's no real solution how to get the encoding of the page where the PHP is run, as it's a server side execution of the script and there I have no access to what will be the output when it's done.
One solution would be getting the file contents that is currently being processed, but there would be an infinite loop...

Anyway thanks, for help I'll give you points.
0
 
bitfactoryAuthor Commented:
Thanks for your comments. I have tried iconv before I posted here, but couldn't find the possibility to get the master web site charset ... Anyway, I have been thinking a lot about this and in fact there's no real solution how to get the encoding of the page where the PHP is run, as it's a server side execution of the script and there I have no access to what will be the output when it's done.
One solution would be getting the file contents that is currently being processed, but there would be an infinite loop...

Anyway thanks, for help I'll give you points.
0
 
The_Blasted_OneCommented:
You're welcome.
Simply check "character encoding" in your browser with your own eyes to know master page's charset.  As I said, checking it with script by fetching the output page via http will bring the performance to the knees.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now