戻る

PHPの4つの記述方法

★ 記述方法1

<?php
header("Content-type: text/plain; charset=utf-8");
echo "こんにちは";
?>

★ 記述方法2

C:\xampp\php\php.iniの設定で「short_open_tag = On」になっているか確認してください。php.iniの設定を変更した場合はapacheを再起動します。

<?
header("Content-type: text/plain; charset=utf-8");
echo "こんにちは";
?>

C:\xampp\php\php.ini

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
;short_open_tag = Off
; XAMPP for Linux is currently old fashioned
 short_open_tag = On

; Allow ASP-style <% %> tags.
; http://php.net/asp-tags
asp_tags = Off

; The number of significant digits displayed in floating point numbers.
; http://php.net/precision
precision = 14

★ 記述方法3

C:\xampp\php\php.iniの設定で「asp_tags = On」になっているか確認してください。php.iniの設定を変更した場合はapacheを再起動します。

<%
header("Content-type: text/plain; charset=utf-8");
echo "こんにちは";
%>

C:\xampp\php\php.ini

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
;short_open_tag = Off
; XAMPP for Linux is currently old fashioned
 short_open_tag = On

; Allow ASP-style <% %> tags.
; http://php.net/asp-tags
asp_tags = On

; The number of significant digits displayed in floating point numbers.
; http://php.net/precision
precision = 14

★ 記述方法4

<script language="php">
header("Content-type: text/plain; charset=utf-8");
echo "こんにちは";
</script>

inserted by FC2 system