Back to DFS's Workshop Page
Back to Agenda Page
Your First Script
Your first script will generate the traditional "Hello, World!" greeting on the command line. Follow the simple steps below.
Type
cd
to get to your home directory.
Type
mkdir public_html/test_php
to create a new directory called PHP.
Type
cd public_html/test_php
to descend into the newly created directory.
Using vi, vim or some other editor, create a new file called helloworld1.php.
Type in the following lines:
<?php
echo "Hello, World!\n";
?>
From the command line inside the test_php directory which you created, type
php -f helloworld1.php
Notes
- <?php informs PHP (or a server) that the following is PHP code.
- ?> informs PHP (or a server) that it has reached the end of the PHP code.
- echo is a function which outputs the specified information. Here the words Hello, World! are printed. The quotation marks enclose what is to be printed. The \n is the newline character.
- The semicolon (;) terminates the single PHP statement, just as in C, C++ and Java.
- The -f you typed in the command string tells the PHP executable that the next element is the file to be processed.
© DFStermole: 2002-2005
Created: 22 Sept 02
Last Modified: 25 Oct 05