back || home || next

Tutorial 1: Beggining

Creating your first php script

<?php

print "Hello Web!";

?>

 

If you type this in a note pad and save it as first.php, his will print “Hello Web!” into your web browser as follows.

If you have not installed PHP your code will not be recognized and it will simply print the whole php code wrote into the web browser.                  

<?php is the starting tag of the php script

?>  is the ending tag of the php script

Print “text”; The print function prints the text inside the double quotes.

The print() Function

 

print() is a function that outputs data. In most cases, anything output by print() ends up in the browser window. A function is a command that performs an action, usually modified in some way by data provided for it. Data sent to a function is almost always placed in parentheses after the function name. In this case, you sent the print() function a collection of characters, or string. Strings must always be enclosed by quotation marks, either single or double.

 

NOTE : The print function does not require paranthesis to function optional.

You can combine php with HTML with proper use of php and HTML tags.

<HTML>

<HEAD><TITLE>My First php script</TITLE>

</HEAD>

<BODY>

<B>

<?php

 print "Hello Web!";

?>

</B>

</BODY>

</HTML>

As you can see, incorporating HTML into a PHP document is simply a matter of typing in the code. The PHP interpreter ignores everything outside PHP open and close tags. You would see the string "hello world" in bold. If you were to view the document source, the listing would look exactly like a normal HTML document.

You can include as many blocks of PHP code as you need in a single document, interspersing them with HTML as required. Although you can have multiple blocks of code in a single document, they combine to form a single script. Anything defined in the first block (variables, functions, or classes, for example) usually will be available to subsequent blocks.

 

Adding Comments

 

Single line comments begin with two forward slashes (/ /) or a single hash sign (#). All text from either of these marks until either the end of the line or the PHP close tag is ignored.

 

// this is a comment

# this is another comment

Multiline comments begin with a forward slash followed by an asterisk (/*) and end

with an asterisk followed by a forward slash (*/).

/*

this is a comment

none of this will

be parsed by the

interpreter

*/

                                 back || home || next