개발/PHP

1. 기본문법

희묭 2024. 3. 28. 09:38

PHP Tag 

<?php echo 'if y  use these tags'; ?>

여러 방법이 있지만 가장 정석적인 방법

<?php
echo "Hello world";
echo "Last statement";

HTML 없이 PHP만 사용하게될경우 php tag 닫는 부분을 생략해주는것이 좋다

 

HTML 사이에 넣기

<p>This is going to be ignored by PHP and displayed by the browser.</p>
<?php echo 'While this is going to be parsed.'; ?>
<p>This will also be ignored by PHP and displayed by the browser.</p>

HTML 태그사이에 PHP코드를 삽입하여 HTML 내용을 변경시킬수 있다.

<?php if ($expression == true): ?>
  This will show if the expression is true.
<?php else: ?>
  Otherwise this will show.
<?php endif; ?>

IF문 적용

<?php for ($i = 0; $i < 5; ++$i): ?>
Hello, there!
<?php endfor; ?>

FOR문적용

주석

<?php
    echo 'This is a test'; // This is a one-line c++ style comment
    /* This is a multi line comment
       yet another line of comment */
    echo 'This is yet another test';
    echo 'One Final Test'; # This is a one-line shell-style comment
?>

다양한 주석처리 방법이 있다

<h1>This is an <?php # echo 'simple';?> example</h1>
<p>The header above will say 'This is an  example'.</p>

#과 //은 ?>는 주석대상에서 제외한다

<?php

//======================================================================
// CATEGORY LARGE FONT
//======================================================================

//-----------------------------------------------------
// Sub-Category Smaller Font
//-----------------------------------------------------

/* Title Here Notice the First Letters are Capitalized */

# Option 1
# Option 2
# Option 3

/*
 * This is a detailed explanation
 * of something that should require
 * several paragraphs of information.
 */
 
// This is a single line quote.
?>

공식가이드에서 제시하는 주석처리안이다