拡張子が.phpのファイルでxml宣言を記述する方法

| | Comments (0) | TrackBacks (2)

拡張子がphpのファイル(というか、phpコードが実行される環境)で、
かつphp.iniのshort_open_tagがOnになっていると、XHTMLのxml宣言でエラーが出る。
なぜかというと、インタプリタが<?xml から始まる文字列をphpコードとして解釈するからである。


通常、次のようなerror_logが出力される。


Parse error: parse error, unexpected T_STRING in *.php on line 1


php.ini のshort_open_tag をOffにするのが正しい解決方法だが、
php.ini を勝手に変更してはならないケースでは、次のような回避方法もある。


<?php echo '<?xml version="1.0" encoding="utf-8"?>'."\n" ?>


PHPの仕様に文句をこぼさずに生きていきたいものですね。

2 TrackBacks

Listed below are links to blogs that reference this entry: 拡張子が.phpのファイルでxml宣言を記述する方法.

TrackBack URL for this entry: http://mahata.net/movabletype/mt-tb.cgi/2976

health insurance from health insurance on January 10, 2008 2:22 AM

news Read More

payday loans from payday loans on January 10, 2008 2:25 AM

news Read More

Leave a comment

About this Entry

This page contains a single entry by mahata published on October 3, 2007 2:06 AM.

ソースコードをブログ(MT)に貼り付けられる形式に変換するツール was the previous entry in this blog.

MovableTypeで変数の値で条件分岐 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.