A php tutorial for beginners

Posted on December 1, 2007 
Filed Under php, tutorial

Taken directly from PHP’s home, PHP.net, “PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.”

This is generally a good definition of PHP. However, it does contain a lot of terms you may not be used to. Another way to think of PHP is a powerful, behind the scenes scripting language that your visitors won’t see!

 

When someone visits your PHP webpage, your web server processes the PHP code. It then sees which parts it needs to show to visitors(content and pictures) and hides the other stuff(file operations, math calculations, etc.) then translates your PHP into HTML. After the translation into HTML, it sends the webpage to your visitor’s web browser.

Creating first php enabled page

Create a file named hello.php and put it in your web server’s root directory (usually www or htdocs) with the following code.

<?php echo‘Hello World!!’;?>

now open the web browser and type
http://localhost/hello.php
or http://127.0.0.1/hello.php. This file will be parsed by PHP and the following output will be sent to your browser

Hello World!!

Forms and PHP

Credate a simple file called test.html which contains the code as follows :
<form action=”first.php” method=”post”>
<p>Your name: <input type=”text” name=”username” /></p>
<p>Your age: <input type=”text” name=”age” /></p>
<p><input type=”submit” /></p>
</form>

now the code of the action.php look like this and these both files shoule be in the same folder.

 

Hi echo <?php echo $_POST['username']; ?>.
You are echo <?php echo $_POST['age'];?>years old.

A sample output looks like this

Hi Michael. You are 28 years old.

Popularity: 2% [?]

Enter your email address and get recent tutorials, tips, tricks and scripts of PHP, Ajax, JavaScript and CSS directly delivered to you email inbox:

Follow me on twitter at http://twitter.com/roshanbh.

Related Posts

» A ajax tutorial for beginners
» This blog’s Code and content is stolen - Please help
» How to display pop-up message on mouse clicked position using jQuery
» Top Floating message box using jQuery

Comments

One Response to “A php tutorial for beginners”

  1. Jeremy on March 25th, 2008 12:20 am

    This post is copied on another website without a link back to your original post or any credit to you. I found your original here by Googling the title. Check out
    http://www.virtisys.com/2008/03/23/phpwhat-is-it/

    I have contacted the hosting company for virtisys regarding copyright infringement of my own work (they ripped off one of my posts as well). You might consider doing the same. Or if you don’t care, then please pardon the interruption.

    Cheers,
    Jeremy

Leave a Reply