Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default php header()

Tags:

php

header

When I create the non-English pages (for example, Russian) I have to use header() to set page's charset (I use UTF-8):

header('Content-Type: text/html; charset=utf-8');

But all my pages should have UTF-8 charset, is there a propery in php to set it by default (I mean: I don't want to set it every time).

like image 960
mirelana Avatar asked May 05 '26 12:05

mirelana


1 Answers

You can use the .htaccess file to do it:

AddDefaultCharset UTF-8

If you want something a bit more robust, you can specify this charset type for only specific file types:

<FilesMatch ".(htm|html|css|js)$">
    AddDefaultCharset UTF-8
</FilesMatch>

Also see this article for other ways of doing it: http://www.askapache.com/htaccess/setting-charset-in-htaccess.html

like image 154
Craig Sefton Avatar answered May 08 '26 01:05

Craig Sefton