Thursday, 30 August 2012

Episode 2 : Creating Your First Program


You can’t get much simpler than this first program, but try it out to get a feel for what the results look like. The PHP function echo, seen in the material that follows, is one of the most commonly used PHP functions.

1. Enter the following program in your favorite text editor (Notepad, WordPad, or whatever), and save it as firstprog.php. Make sure you save it in a “plain text” format to avoid parsing problems, and if you’re using Notepad, double-check to ensure that the file is not saved as firstprog.php.txt by default.

<html>
<head>
<title>My First PHP Program</title>
</head>
<body>
<?php
echo "Hello Everyone! This is my first PHP program.";
?>
</body>
</html>

2. Open this program using your browser. Your resulting screen should look like the one in Figure
 
3. Now view the source of the HTML code so you can see what happened with the PHP portions of the code. As you can see, the PHP portion of the code has vanished, leaving only the resulting HTML code.
4. Now add the following highlighted line to your script so you can get a better feel for how your PHP code will be parsed:

<html>
<head>
<title>My First PHP Program</title>
</head>
<body>
<?php
echo "Hello Everyone! This is my first PHP program.";
echo “And I’m okay.”;
?>
</body>
</html>

5. Save the revised file and open it in your browser. As you can see, the line runs together without a line break, even though you had your PHP code on two different lines.


Written by “Shojib”.

No comments:

Post a Comment