Sunday, May 4, 2014

PHP Eclipse 101: Getting Started

-----
PHP Basic 101 Using Eclipse IDE (Hello World)

INTRODUCTION

This tutorial is adapted from http://www.w3schools.com/php/php_syntax.asp .

STEPS

1) Create a new project basic101.

If the item “PHP Project” doesn’t appear in the menu, select “Other…” and select “PHP Project” in the provided list.

2) Creating PHP Hello World program.

2.1) Right-click the project name and select New/PHP File.
2.2) 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.
2.3) 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 )

3) Creating PHP Comments.


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>

4) PHP Code Case Sensitivities.


codecase.php
<!DOCTYPE html>
<html>
<body>
<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>
</body>
</html>




4) PHP Variable Case Sensitivities


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.
-----

No comments:

Post a Comment

Labels