PHP 구문의 모든 유형에서 조건에는 대괄호가 필요합니다.
<?php if (!isset($_GET["bodyonly"])): ?><html>
<head>
<title>TEST</title>
</head>
<body>
<p>Up!</p>
<?php endif; ?><p>Down!</p><?php if (!isset($_GET["bodyonly"])): ?>
</body>
</html><?php endif; ?>
또한 코드에 최신 구조를 사용하는 것이 좋습니다. 중괄호와 PHP를 HTML 래퍼가 아닌 프로그래밍 언어로 사용하면 조건 적으로 실행되는 내용을 매우 쉽게 볼 수 있습니다.
<?php
$status="Up";
// $status="Down";
$header="<html>\n\t<head>\n\t\t<title>TEST</title>\n\t</head>\n\n <body>\n";
$footer=" </body>\n</html>\n";
if (!isset($_GET["bodyonly"])) {
print $header;
}
printf("\t<p>%s</p>\n", $status);
if (!isset($_GET["bodyonly"])) {
print $footer;
}
또는, 심지어 그것의 재미를 위해 :
<?php
$status="Up";
// $status="Down";
$header="<html>\n\t<head>\n\t\t<title>TEST</title>\n\t</head>\n\n <body>\n";
$footer=" </body>\n</html>\n";
print isset($_GET["bodyonly"]) ? "" : $header;
printf("\t<p>%s</p>\n", $status);
print isset($_GET["bodyonly"]) ? "" : $footer;
또는 (이 그냥 바보지고) :
<?php
$status="Up";
// $status="Down";
$header=""; $footer="";
if (!isset($_GET["bodyonly"])) {
$header="<html>\n\t<head>\n\t\t<title>TEST</title>\n\t</head>\n\n <body>\n";
$footer=" </body>\n</html>\n";
}
print $header . sprintf("\t<p>%s</p>\n", $status) . $footer;
는 PHP에서 instructions on syntax에서보세요. 그물.
무엇입니까? 'if! isset ($ _ GET [ "bodyonly"]) :' – Sebas
괄호 안에'if' 조건이 오타가 있지 않습니까? 대체 구문 AFAIK에도 필요합니다. – Shoaib