PHP Basic 101 Using Eclipse IDE
This tutorial is adapted from http://www.w3schools.com/php/php_syntax.asp .
If the item “PHP Project” doesn’t appear in the menu, select “Other…” and select “PHP Project” in the provided list.
2.1) Right-click the project name and select New/Folder.
2.2) Type the folder name, 101.
3.1) Right-click the folder 101, select New/PHP File.
3.2) Type the File Name helloworld.php.
3.3) Type the following codes:
helloworld.php |
<!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html> |
black color= HTML codes.
red color= PHP codes.
3.4) Right-click the file helloworld.php, select Run As/PHP Web Application.
(If you have a problem of executing this script file on a web server, follow this this tutorial, http://php-steps.blogspot.com/2014/05/php-program-development-using-eclipse.html )
comments.php |
<!DOCTYPE html> <html> <body> <?php // This is a single line comment # This is also a single line comment /* This is a multiple lines comment block that spans over more than one line */ ?> </body> </html> |
(Take note that this script doesn’t produce any output).
codecase.php |
<!DOCTYPE html> <html> <body> <?php ECHO "Hello World!<br>"; echo "Hello World!<br>"; EcHo "Hello World!<br>"; ?> </body> </html> |
variablecase.php |
<!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> |
You should get a warning message “Undefined variable” for COLOR and coLOR variables.
To turn off the error message, go to UwAmp Control Panel, click PHP Config, click PHP Setting, click Display Errors item and change the value to Off.
Refresh your browser.
Since we are now in the development stage, set the Display Errors value back to On so that the server could tell you the problems in your codes.