LoginSignup
7
6

More than 5 years have passed since last update.

htmlファイルにphpを導入させる方法

Last updated at Posted at 2015-06-02

導入したいディレクトリに.htaccessを作り、
AddType application/x-httpd-php .html
サーバによっては、
AddHandler application/x-httpd-php .php .html
の場合もある?

htmlソースによっては、これだけだと
Parse error: parse error, unexpected T_STRING in ~(ファイル名) on line 1
といったエラーが出る。
これは
<?xml version="1.0" encoding="utf-8"?>
が書かれていると、"<?"がphpだと認識してしまうため。
よって、.htaccessに
php_flag short_open_tag Off
という記述を追加する。

追記:

.htaccessにphp_flag short_open_tag Offと書くより、
<?xml version="1.0" encoding="utf-8"?>

<?php echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; ?>
と書くほうが確実そう。

7
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6