PHP is a widely used open source server side scripting language that is used to create dynamic and interactive web pages. PHP can be directly embedded into the HTML code and hence, is perfect for any web development. The syntax of PHP is very similar to Perl and C. PHP works on Apache web server and also supports Microsoft Internet Information Server.
If you want to use PHP for website and web applications you need three things; PHP itself, a web server and web browser. To design and develop web pages you need a web development application. In addition, if you want to create dynamic web pages, you might also need database functionalities.
I suggest you to install WampServer and Macromedia Dreamweaver. WampServer is a Windows web development environment that comes with Apache webserver, PHP and MySQL database. You can download WampServer for free using this link http://www.wampserver.com/en/download.php. For more information on how to install WampServer visit this link, http://www.wampserver.com/en/presentation.php.
PHP block starts with and can be placed anywhere in HTML code. Each line of code ends with semicolon. Semicolon is used to separate one set of instructions from another. The example below is a simple PHP script which sends the message “Hello World” to the browser.
Create a file and save it with name example1.php and paste the following code. This code is extremely simple, contains HTML tags and a block of PHP script. The highlighted portion of the code is PHP code and is embedded into HTML. The whole file needs to be saved with .php extension, if the file has other than .php extension like .html, the PHP script will not execute.
The file can be accessed using browser with web server’s URL, ending with the /example1.php file reference. For example if you are developing locally, the URL will look like http://localhost/example1.php.
Example# 1:
<html> <head> <title>First Example</title> </head> <body> <?php echo "Hello World"; ?> </body> </html>
For comments, // or # is used for single line comment and /* and */ is used for multi line comments. Now amend the file as follows. The output will remains the same, why?.
Example# 2:
<html>
<head>
<title>Example with comments</title>
</head>
<body>
<?php
//Single line comment or
#Single line comment
echo"Hello World";
/*
Multi line comment
Line 1
Line 2 ...
*/
?>
</body>
</html>
Normally, most of the programming languages are strongly typed and require the data type while declaring variables but PHP does not need to declare data type before being set. PHP automatically declare variable and the type of variable is determined at the run time depending on the context in which that variable is used. In PHP, a variable is identified by placing a $ in front of variable name. Variable name are case sensitive.
Example# 3:
<?php
$x = 10;
$y=20;
$z = $x + $y; // $z=$X+$Y does not produce result 30, because variable names are case sensitive.
echo "The result is: ". $z; // Output will be 30
$name ='John';
$Name= "Mary";
echo "$name, $Name"; // The output will be John, Mary
?>
In the above example $ sign before x, y and z specifies that they are variables. The types of the variables are determined when they are being assigned. 10 determine the type of variable x, 20 determine the type of y and the result of x+y determines the type of z. We will discuss more about the types, assignment and predefined variables in the following tutorials.
RSS feed for comments on this post. TrackBack URL
Hi really nice one, really looking forward for next parts
cheers
You won’t have to wait long.
hey
more informative plz forward remaining parts
I found a great article about PHP for newbies
I found a good article about PHP for newbies here
visit
http://cbabeesh.blogspot.com/
I will definitely be returning here tomorrow ( after Ive slept a bit
) and I will def be studying all of these tuts ( so I can gain some insight & know what the heck Im doing – before I end up blowing up the web
) . * Please list your 1-800 number for newbies like me
ya think u can ?
– * I shall return ! Great tuts & rockin articles !
M.
** P.S: FIX ur Retweet Button – it shouldnt say RT@tweetmeme – it should be RT@ USERNAME – Im shocked !
* anyway , fix it
Catch ya in cyberspace !
@Mia Fixed
Good hackey
– but I just noticed Bab’s comment ^ – that is too funny LOL : why would someone be writing PHP scripts and be on Blogger ? If they possess such expertise at PHP why not be on WP & back up what theyre writing about ?? Im sorry I cant stop laughing at that I find it so funny
Excelente! Muchas Gracias.