Search This Blog

Thursday, March 5, 2009

PHP: Simple hello world script

Starting with PHP

here we going to write some simple PHP scripts to see how we can deveop a web page using PHP.

first of all , there should be a web Server installed in your computer so that we can browse for our web page. It is better if you have apache server installed or else one of the server bundle from XAMP [this has for both windows and linux ],WAMP [for windows users],LAMP [linux users].
if you are a windows user and already you have IIS installed then donload PHP binaries from www.php.net wich is official web site for PHP and install it in your computer ..

After these step now we can sart development of our web pages with PHP. later appliations we can go to dance scripts even with db connections and web services, xml ,sockets, pdf, etc.. we may need some additional libraries to do programming in rlated to above mentioned things.. any way later with my applications im going to use mySql as my database serer. it is also a open source and free to download the free version and its better if u can download it and insatall it n your computer.

seem that is enough for basic hre will star our web tutorial..

first open up a text editor on your computer. we dont need any spacial IDE to do this exaple.. its really enough to have a saml text editor tool.

the php scripts realy starts with <?php tag and it is end with ?>. actually what ever the php conent is gone within this tag. other wise it is not executed by the php engin/web server .

see complete sample php file to our example.

mytest1.php
---------------
<html>
<head>
<title>PHP: Our sample Hello world application</tittle>
</head>
<body>
<?php

echo "Hello : You are wel come to my web site";
// we are done, our first example

?>
</body>
</html>

This is one of the way that we can print string into the response web page. ther is onether way we an do this that is without including html tags. any way i dont recomend that way to use web pages except for the class files written in php.

i.e :

<?php

echo "Hello : You are wel come to my web site";
// we are done, our first example

?>

ok, now we go to explanation above example.

echo(); is the function that prints any out put to the page.

you can see that the out put is enclosed within the double quatation marks " " this tells the server that this is the string which should be print onto the response. there is one of other way to do this. that is using the single quotation mark
' ' see the following example.

i.e
<?php

echo
' hello : You are wel come to my web site';
// we are done, our first example

?<

why there is two ways of doing this ? what is the difference between these two? guess..? actually it has difference. when you use single quot '' to echo something echo will print all the string same as it is appears to our eye. there is no limitation of escape character sequenes or som eother else.

but if you are using double quot "" then the out put is change.. say you have some escape character within the double quat then echo will for sure escape those character and print he output..

will learn those in next tutorial..
here lm gonna take a shower
thank you.
semiolon ( ; ) is the operator we used to tell that this is the end of the line.