![]() |
Web Conference 2005Writing PHP for ITS/ASET Web servicesYour First PHP Script |
![]() |
| <- Back - Penn State Specifics | | | Up | | | The PHP Language - Next -> |
Connect to your Web space.
For the examples below, we will use the PASS Gateway.
Begin by opening a text editor such as Notepad and write the following content (copy/paste into your editor):
<html>
<body>
<p>This is a simple Web page.</p>
</body>
</html>
Use the Notepad
tutorial if you are new to editing text files, copy/paste, or
saving content to your Web site.
Next, save this content as a new file called firstphp.html in the phpclass sub-folder of your Web space.
If you have not created a phpclass sub-folder, you should do that now to keep you class examples separate from the rest of your site.
Your Penn State Personal space is the www folder of your PASS. The page should be visible
as http://www.personal.psu.edu/users/x/y/xyz123/phpclass/firstphp.html.
It should read, "This is a simple Web page."
Now, rename the file in to be firstphp.php and view it as http://www.personal.psu.edu/x/y/xyz123/firstphp.php. It should look the same, however you may notice the server name in the URL automatically changed from www.personal.psu.edu to php.scripts.psu.edu.
So we have seen PHP (.php) pages are really just specialized HTML (.html) pages. Let's add some dynamic content. Edit firstphp.php to appear as follows:
<html>
<body>
<p>This is a simple Web page.</p>
<b><?php echo "<p>With a little PHP</p>\n"; ?></b>
</body>
</html>
View the page again. It should have the two lines written above. Now look at the source HTML of the file (how to view source). You should see how the second paragraph has been added, but you don't see the "php" or "echo" text.
Let's examine the php code:
It begins with <?php and ends with ?>. These tags mark the beginning and end of a section of PHP code.
There is a single command of echo, which means, "write the following text on the screen." The double quotes enclose the text that is to be written, and the command is concluded with a semicolon.
Inside the quotes is the text \n, which means, "place a line-break here." Note that this is a line-break in the HTML code, not when the code is viewed in a browser. That would take a <br> tag.
| <- Back - Penn State Specifics | | | Up | | | The PHP Language - Next -> |
|
If you have any questions, feel free to ask me. Content by: Jeff D'Angelo <jcd@psu.edu> © 2005 Last update on: Sat Jun 11, 2005, 8:20:31 PM |
|