Getting To Know PHP

Published: 07th December 2011
Views: N/A
Ask About This Article Print Republish This Article
Well first things first, PHP is a scripting language that is server side, by server side I mean the people viewing the web page containing the script doesn’t have to download anything to get it to work.
The main reason people use PHP is because their website are dynamic, the use of PHP script will allow the designer to create pages that can change on certain circumstances. PHP script can be use to do many things, add water marks to images on the fly, meaning you upload your image and the code will automatically add the water mark over the top of them without you needing to do anything. There is only one major thing that PHP can’t do, and that is real time processes meaning the page that the script is on needs to be load or reloaded to run the script.
In this article I will show you have to learn the very basics about PHP and how to get a script to work.
First of all you’ll need to make sure the web server that your webpage/script is on allows the use of PHP most does these days but they are still some out there that don’t. Once you know that your server supports PHP you can get to create the file.

In any type of webpage you’re going to need some of the basic HTML tags to ensure that the script we create is going to be visible on screen. So we will start with the html and body tags.


//this is where your code is going to be!!


These tags will allow you to display your script output, copy an paste these into your notepad or web page editor software.
Once you’ve done this you will want to save your page as a .php file e.g. yourfilename.php this will tell your web server that the web page contains PHP script that will need to be run when the file is accessed.
So now we have a very basic empty web page we are now going to fill it with some PHP code! We will start off with some VERY basic stuff. First we want to say hello to anyone that visits the web page so to do that we’ll add a simple bit of code that will display some text. When starting your PHP script you need to open the script almost in the same way as a normal HTML tag but you don’t close the tag until your script is finished e.g. .

So our code to say hello is:
echo “Hello, Welcome to my web page”;
?>
You’ll notice that there is a semi colon after t the code, this is needed to tell the server that, that line of the script is ended, if the semi colon isn’t there the script will crash and the page will fail to load or will load incorrectly.
We want to make the people who view the page feel welcome so we will add a nice little form and get them to enter their name so when they view the page it says “Hello (views name), Welcome to my web page”. This can be done easily once we’ve added a form to the page, copy the code below for the form.
?>




} // here instead of echoing the form out we close the script and then reopen it to finish of the if statment
?>
This will allow the user to enter their name, once they have and they click submit the form will disappear. We now need to add some more code to display the text, so the end code should look like this.


?>




// here instead of echoing the form out we close the script and then reopen it to finish of the if statement
} else {
$name = $_POST[‘user’];
echo “Hello “.$name.”, Welcome to my web page”;
?>


It’s that simple, you can use this code in any web page that uses PHP script to display names or anything else they type into the text field on the form.

This article is free for republishing
Source: http://nickhatton.articlealley.com/getting-to-know-php-2396573.html


Report this article Ask About This Article Print Republish This Article


Loading...
More to Explore
 


Ask a Professional Online Now
27 Experts are Online. Ask a Question, Get an Answer ASAP.
Type your question here...
Optional:
Select...