Forum Moderators: coopster

Message Too Old, No Replies

AddDefaultCharset and PHP

         

Jeremy_H

8:59 pm on Jan 11, 2006 (gmt 0)

10+ Year Member



I notice that my .html files will validate if my charset is only specified once in my .htaccess file.

However, my .php will not validate on the same server.

Can I use AddDefaultCharset for PHP files?

Thanks

coopster

10:19 pm on Jan 16, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The problem likely lies in the fact that this Apache directive [httpd.apache.org] specifies a default value for the media type charset parameter (the name of a character encoding) to be added to a response if and only if the response's content-type is either text/plain or text/html.

I said likely, so you may want to have a closer look at a couple of PHP variables in your configuration ...

default_charset [php.net]
default_mimetype [php.net]

... as well as reviewing response headers [webmasterworld.com] on your site page(s) in question.

Jeremy_H

7:25 am on Jan 17, 2006 (gmt 0)

10+ Year Member



Thank you coopster for your post.

So my understanding is the .htaccess AddDefaultCharset will only work for text/plain or text/html files. PHP files are not text/plain or text/html so it will not work by default.

I could use default_charset in each of the PHP files (versus globally through the .htaccess file), but I could always do that through the META tag. In which case, it would probably be better just to keep the META tag.

I could also use default_mimetype to "trick" the browser into thinking the PHP document is text/plain or text/html, in which case an .htaccess file might work, but there might be rendering problems with this, and I'd still have to have a setting (although a different type of setting) for each of the PHP pages. So this would be a bad idea.

There is no way to change the .htaccess file to make AddDefaultCharset work for PHP files.

So the best way to keep all my PHP pages valid is just to define the charset in each and every page.

Is my understand correct? If so that sucks :(. But again, thanks for all your help.