PHP基礎指令與編撰方式基本介紹(字串、變數、陣列與基本識別符號)

在編撰PHP內容時,PHP編譯器首先會找到識別範圍。
如:
<?php
          此為PHP編譯器識別範圍~
?>
運用簡單的輸出指令echo來將字元輸出給html(畫面),這個echo指令與C的printf相似,當然在php也可以使用printf來輸出變數....等等。
至於在html畫面上若需要換行,需要加上html換行的字元<br/>,但它不會再php運行畫面上做換行,必須加上與c相同的換行字元\n。
另外撰寫過程中,註解方式與C相同,單行//,範圍/*~~*/。
分號'';''也是和C一樣為指令結束。
因為PHP為了加快其編譯速度,所以用$符號去判斷其後面變數屬性,在PHP不需要像C宣告型態int...char....(用$即可)。
字串$a="hi",$King="Queen's husband"; ("需要雙引號")
數值$a=10,
陣列$a=array(''H'',''i'',''apple'',''book'');或$a=array("52","20","69");
二維陣列$a=array(array(''H'',''i''),
                              (''apple'',''book''),
                              ("cut","dreams"));
複製方式$user=$King;

基本中的基本練習~
<html>
        <head>
                <title>測試頁面</title>
        </head>
        <body>
                <?php
                $boy=array('John','Jack','Jason');//陣列
                echo $boy[1],"<br/>\n";              //印出jack+html&PHP換行
                echo ("used echo to print Hi PHP<br/>\n");
//              echo ("used echo to print Hi PHP<br/>");僅在html上換行
                printf("used printf to print word<br/>\n");
/*              printf("used printf to print word\n");僅在php運行上換行*/
                ?>
        </body>
</html>

留言