ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [PHP] 2. 문법(Syntax) - PHP 강좌, PHP5
    Web/PHP 2015. 6. 13. 11:54

    PHP 5 Syntax

     PHP 스크립트는 서버에서 실행됩니다, 그리고 일반적인 HTML 결과를 브라우저에 보냅니다.





    1. Basic PHP Syntax

     PHP 스크립트는 문서의 어디에나 위치할 수 있습니다.


     PHP 스크립트는 <?php 로 시작해 ?> 끝납니다.


     문법:

    <?php
    // PHP code goes here
    ?> 




     PHP 파일의 기본 파일 확장명은 ".php" 입니다.


     PHP 파일은 일반적으로 HTML 태그와 몇몇의 PHP 스크립팅 코드를 포함합니다.


     예제: PHP 내장 함수인 echo를 사용하여 텍스트 "Hello World!"를 출력하는 예제입니다.




    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <!DOCTYPE html>
    <html>
    <body>
     
    <h1>My first PHP page</h1>
     
    <?php
    echo "Hello World!";
    ?>  
     
    </body>
    </html>
    cs
     





    2. Comments in PHP

     PHP 코드에서의 주석은 프로그램의 일부로 읽지 않거나, 실행되지 않는 라인입니다.



     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <?php
    // This is a single-line comment
     
    # This is also a single-line comment
     
    /*
    This is a multiple-lines comment block
    that spans over multiple
    lines
    */
     
    // You can also use comments to leave out parts of a code line
    $x = 5 /* + 15 */ + 5;
    echo $x;
    ?>
    cs






    3. PHP Case Sensitivity

     PHP에서 모든 키워드(if, else, while, echo, 등등), 클래스, 함수, 사용자-정의 함수는 case-sensitve하지 않습니다.


     아래 예제는 3개의 echo 문이 동일하다는 것을 보여줍니다:



    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <!DOCTYPE html>
    <html>
    <body>
     
    <?php
    ECHO "Hello World!<br>";
    echo "Hello World!<br>";
    EcHo "Hello World!<br>";
    ?>
     
    </body>
    </html>
    cs
     





     






     그러나, 모든 변수 이름은 case-sensitive 합니다.


     아래 예제에서 첫 번째 echo 문만 $color와 일치하므로 red를 출력합니다.





    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <!DOCTYPE html>
    <html>
    <body>
     
    <?php
    $color = "red";
    echo "My car is " . $color . "<br>";
    echo "My house is " . $COLOR . "<br>";
    echo "My boat is " . $coLOR . "<br>";
    ?>
     
    </body>
    </html>
    cs




     


     





     


    * 이 강좌는 'w3schools'를 참조하여 작성하였습니다.

    댓글

Designed by Tistory.