Gray Hat World - Internet Marketing Forum

Full Version: [Tutorial] Getting started
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Getting started with php


Getting started in Php

Lets get to know the common, useful functions of Php...

A php file uses an extension of : .php | Example : index.php
When you start a php file you will always use "<?php" to start the script, and to close the script you use "?>".
Example :
PHP Code:
<?php

?>

Php files normally contain HTML tags, just like HTML files, and some php scripting code.

Here is an example of a simple Php script which sends the text "Hello World" to the browser.
Example :
PHP Code:
<html>
<
body>
<?
php
echo "Hello World";
?>
</body>
</html> 

Each php code line ends with a semicolon ";" this is used to separte one set of instructions to another.

There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".

Note: The file must have a .php extension. If the file has a .html extension, the PHP code will not be executed.


Php Comments

Php comments can be quite important, obviously to help you remember and guide you, but if you release a php file, you normally write about each part of the script.

To start a comment beside/above/below the script you must use "//"
If you are doing more than one line comment you must use "/*" followed by "*/"

Example :
PHP Code:
<html>
<
body>
<?
php
// This is a single line comment

/*
This is
a comment
on more than
one line
*/

?>

</body>
</html> 

Enjoy, and make sure you don't miss out on the next tutorial..
very useful i think. and more clear than the *How To* guides i have googled Smile

(but still dont get a thing >.<.... examples. wer did u kno to add <body> and what it does)
and
<html> // why this?
<body> // n what this does?
<?php // this i know. it starts the script rite?
echo "Hello World"; // why echo?
?> // this ends the script if im rite
</body> // these again :/
</html> // - || -
(07-10-2009 07:10 AM)ffs Wrote: [ -> ]very useful i think. and more clear than the *How To* guides i have googled Smile

(but still dont get a thing >.<.... examples. wer did u kno to add <body> and what it does)
and
<html> // why this?
<body> // n what this does?
<?php // this i know. it starts the script rite?
echo "Hello World"; // why echo?
?> // this ends the script if im rite
</body> // these again :/
</html> // - || -

Oh Well <html> is like the website code, you always start with when making a full web page.
<body> is the body of the web page.
<?php is the script yes
echo "" prints text


</">
ends code.
nice tutorial i think ^^
Reference URL's