Syntax ng PHP
- Previous Page Pag-install ng PHP
- Next Page Variable ng PHP
Rekomendasyon ng kurso:
Ang script ng PHP ay isinasagawa sa server, at pagkatapos ay ipinapadala pabalik sa browser bilang plain HTML result.
Bastangyong sintaksis ng PHP
Ang script ng PHP ay maaaring ilagay sa anumang lugar sa dokumento. <?php Simula, na may ?> Tapusin, na may
<?php // Ito ay kodigo ng PHP ?>
Ang kasalukuyang file extension ng PHP file ay ".php".
Ang mga file ng PHP ay karaniwang naglalaman ng mga tag ng HTML at ilang kodigo ng PHP.
Ang sumusunod na halimbawa ay isang simpleng file ng PHP, na naglalaman ng isang pangungusap na PHP na gumagamit ng naibangong function ng PHP "echo" upang magpalabas ng teksto "Hello World!" sa web page:
Example
<!DOCTYPE html> <html> <body> <h1>Ang aking unang pahina ng PHP</h1> <?php echo "Hello World!"; ?> </body> </html>
Komento:Ang mga pangungusap sa PHP ay nagtatapos sa pahina ng koma (;). Ang tagpangalaga ng bloke ng kodigo sa PHP ay magiging koma din ang awtomatikong ipakita (kaya hindi kailangan ng koma sa huling linya ng bloke ng kodigo sa PHP).
Ang mga komento sa PHP
Hindi mababasa at maitatayo bilang programa ang mga komento sa PHP. Ang kaisa-isang ginagamit nito ay para sa pagbabasa ng tagapagwasto ng kodigo.
Ang mga komento ay ginagamit para sa:
- Huwag mawawala ang pag-iisip ng iba tungkol sa ginagawa mo ng trabaho - ang mga komento ay maaring makilala ng ibang programmer ang ginagawa mo sa bawat hakbang (kung ikaw ay kasapi ng grupo)
- Remind yourself of what you have done - most programmers have experienced having to go back to a project after one or two years and reconsider what they have done. Comments can record your thoughts while writing code.
PHP supports three types of comments:
Example
<!DOCTYPE html> <html> <body> <?php // This is a single-line comment # This is a single-line comment /* This is a multiline comment block It spans Multiline */ ?> </body> </html>
PHP Case Sensitivity
In PHP, all user-defined functions, classes, and keywords (such as if, else, echo, etc.) are not case-sensitive.
In the following example, all three echo statements are valid (equivalent):
Example
<!DOCTYPE html> <html> <body> <?php ECHO "Hello World!<br>"; echo "Hello World!<br>"; EcHo "Hello World!<br>"; ?> </body> </html>
However, in PHP, all variables are case-sensitive.
In the following example, only the first statement will display the value of the $color variable (this is because $color, $COLOR, and $coLOR are considered three different variables):
Example
<!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>
- Previous Page Pag-install ng PHP
- Next Page Variable ng PHP