• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • 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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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