Go Back   Webmaster Forum > Development > Programming > PHP
REMOVE the ads below !
Reply
 
LinkBack Thread Tools
  # 1 (permalink)
Old
Junior Geek
Posts: 142
Join Date: Feb 2007
iTrader: (0)
Post PHP 01 : Hello Word - 09-27-2007

First thing, you have to know some HTML code before trying to use PHP because PHP interact with HTML.

In an HTML page, you can start a PHP code by using this quote :
PHP Code:
<?php blablabla?>
The server have to know you want to use PHP, so you need to save your document as :
mydocument.php and not anymore as mydocument.html

First code :
Open a new document and write :
PHP Code:
<?php echo 'Hello Word'?>
Save it with the php extension and put it on your server, launch it with your browser.

Whaoo you could see "Hello word" on your document. As you can understand 'echo' means display on the browser.
Echo is a function of PHP, like a lot of others as you can see at http://www.php.net

Each function need to be ending by a ";" in order to say that your function is finished (the function not the code). A lot of errors on coding is to forget this ";".


Now you could also insert some html code :
PHP Code:
<?php echo '<b>Hello Word</b>'?>


If we want to comment a code, you could use :
PHP Code:
<?php //my comment on only 1 line ?>
<?php 
/* this other quote
for more than
1 line and must ending by */ 
?>

We saw "hello word", but you can write also :
PHP Code:
<?php $hello='Hello Word'/* This is a variable declared as "$hello",
the $ is necessary, and as each function ending with ";" */
echo $hello/* A simple "echo" ending with ";",
you don't need to use "'" because you don't insert text directly.*/
?>
You can declare as variable you want, with the name you want.
A variable could be a word, a letter or a number or others variable :
PHP Code:
<?php $a='hello';
$b=' w';
$c='ord';
$d='123';?>
You can add number to others numbers, put letter after/before others letters :

PHP Code:
<?php $e=$d+1;
// or it is the same thing
$d=$d+1;
// or again
$d++;
// and also 
$d--;
// means
$d=$d-1;
?>
PHP Code:
<?php 
$f
=$a.$b.$c// the "." means put after
//and then display
echo $f;
// or also
echo $a.$b.$c;
?>


Thanks,
Aqua


-------------------
http://www.aquafolie.org

Last edited by aquafolie : 09-27-2007 at 04:44 PM.
Reply With Quote
Reply


Thread Tools



Advertise Here for just $6 per month

vBulletin®, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd. | SEO by vBSEO | Skin developed by vBStyles.com