Introduction to PHP – Part 1

advertisement

Introduction:

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.

Installing PHP:

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.

Basic Syntax:

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>


Defining Variables:

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.

Naming rules:

  • A variable name must begin with a letter or an underscore “-“.
  • A variable name can only contain characters, numbers and underscore (a-z, A-Z, 0-9 and _).
  • A variable name should not contain any special characters and space.

 

You can check out our latest actualtests lsat practice test braindumps and realtests ged test online braindumps exams written by our certified teams to help you pass certkiller ged test online.

About the Author:

Bhoj R Dhakal is a programmer. He has few years of experience in software development and maintenance. He has published series of PHP tutorials for webanddesigners.

Other News

  • Pingback: » Introduction to PHP – Part 1 | Devmarks

  • http://www.wajerrr.com/flash/ wajer

    Hi really nice one, really looking forward for next parts
    cheers

  • http://www.webanddesigners.com WAD

    You won’t have to wait long.

  • Pingback: Introduction to PHP – Part 1

  • Pingback: Introduction to PHP – Part 1 | Programming Blog

  • Pingback: Introduction to PHP – Part 1 | meshdairy

  • Pingback: Introduction to PHP – Part 1 | Master Design

  • bhanu

    hey

    more informative plz forward remaining parts

  • Pingback: 80+ Awesome Community Links for Designers and Developers | tripwire magazine

  • Pingback: 80+ Awesome Community Links for Designers and Developers | Programming Blog

  • Pingback: 80+ Links for Designers and Developers – รวมมาแล้วบทความสำหรับ Webmaster | ไอทีสนุกดอทคอม

  • Pingback: 80+ Awesome Community Links for Designers and Developers | Master Design

  • http://www.cbabeesh.blogspot.com/ bab

    I found a great article about PHP for newbies

  • http://cbabeesh.blogspot.com/ Bab

    I found a good article about PHP for newbies here
    visit
    http://cbabeesh.blogspot.com/

  • Pingback: Favorites From The Feeds #1: All The Stuffs You Need | AEXT.NET

  • Pingback: Favorites From The Feeds #1: All The Stuffs You Need | Master Design

  • Pingback: Top WordPress Code Sites | Websites for Small Biz

  • http://www.dezigndiva.com Mia

    I will definitely be returning here tomorrow ( after Ive slept a bit :D ) 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 :D ) . * Please list your 1-800 number for newbies like me :) ya think u can ? :P – * I shall return ! Great tuts & rockin articles !

    M. 

  • http://www.dezigndiva.com Mia

    ** P.S: FIX ur Retweet Button – it shouldnt say RT@tweetmeme – it should be RT@ USERNAME – Im shocked ! :P * anyway , fix it :) Catch ya in cyberspace !

  • http://www.webanddesigners.com WAD

    @Mia Fixed

  • http://www.dezigndiva.com Mia

    Good hackey :D – 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 :D

  • Pingback: PHP, the other other white meat « Devin Lynch Design – Blog

  • http://www.dtmpublicidad.com David

    Excelente! Muchas Gracias.

  • hameac2034

    However, take everything you read with a pinch of salt as no prediction is a hundred percent accurate. Learn to trust your own instincts, do your due diligence well, and you should be able to come up with accurate predictions in no time.Some look like dress shoes or sneakers. There are shoes around that look amazing and feel even better.You could have shoes to match any one of one’s outfits and if you would like your gladiator shoes to be versatile, go for a neutral shade like tan, brown or camel.These colors will match most outfits and you may make it much more complementary to your attire by carrying a matching tote or bag.In offensive basketball plays , you have various types of clusters to malfunction the defense. Basketball plays are the foundation of almost any coach’s practice for succeeding.

    With Background Retouching the image is given a suitable background that will work wonders for the entire image.Jewelry Photo Retouching includes Clipping Path, Photo Retouching, Background Retouching, Product Clipping and a lot of other techniques that help your muse to get the desired effect.They make both a fashion statement as well as being comfortable and making you at ease. timberland boots took the world by storm when they were first introduced in the 1970’s.No limit on the number of songs and no restriction on when you can download.These iPod music downloads sites are great money savers.Complete the A items first. This may seem obvious, but think about how many times you’ve put off an important (sometimes unpleasant) task so you could call a friend, clean your room or do something else that really didn’t need to happen at that time.

    Last Tuesday, restaurant operator Darden (DRI), owner of The Olive Tree and Red Lobster, reported the first positive same store sales quarter (+0.5%) since the quarter ended May 31, 2008.Early season fishing (during the spawn) in the western basin is usually done with jigs and crank baits with an occasional troller thrown in. Early in the season you will find the walleye in the shallow water on and around the reefs.Pretty much anything on an infomercial, as far as I can tell, is a sham.Ron Popeil?000 internos, la totalidad de los reos de delitos federales, con una inversi n que cifr en 32.822 millones de pesos.Anyway, here the description from 2K:”Jimmy’s Vendetta takes players into an alternate perspective of the mob through the eyes of Jimmy, the guy the other guys call when they need to finish the job.

    A pair of Nike shoes is a mighty expensive purchase. A whopping $150 for a pair of Nike Shox TL IV is not funny.The reason I haven’t blogged is firstly I was unwell for a couple of months, then it was Christmas and then there was a death in my family.Back in February my sister passed away suddenly in her sleep.Ocular gonorrhea in an adult usually results from autoinoculation from an infected genital site. As in genital infection, the manifestations range from severe to occasionally mild or asymptomatic disease.This time they would not have to face Bill Russell and the Celtics, however. While the Celtics weren around, the Lakers were still unable to win.We are always looking for new freelance writing talent. That is what inspired us to create Article Insider.

    He’s concerned about you after all this time and that should mean that he really cares, right? Well, yes and no.Thus let’s talk concerning the newest product or service of Lebron Wayne shoes. In the following we are debating about the nike air max LeBron VII All-Star Limited Edition.And through the 80’s, the organization expanded its item line to incorporate numerous sports and destinations all through the world. You can discover a large array of running shoes, jerseys, shorts, baselayers and other sportswear excellent for selection of sports.These are usually only sold in stores which specifically carry stripper clothes, but you may also find them at smoke shops and online. Penney, and other popular department stores are not the best places to find stripper clothes, but it is possible to find suitable alternatives there.