Test

Powered by Blogger.

Php Introduction



PHP
 is an extremely popular, Open Source scripting language, most commonly used on webservers to produce dynamic pages. The name "PHP" is a recursive acronym for "PHP: Hypertext Preprocessor" and was initially created by Rasmus Lerdorf in 1994. As of today, the current version of PHP is version 5, with version 6 in the making.

As mentioned, PHP is mostly used on websites, which is what this tutorial will focus on. You may wish to set up your own test server, which is very easy to do, using the next couple of chapters to help you out. If you already have a server up and running, or at least access to a server running PHP 5, you can jump to one of the next sections, where we will start writing some PHP. You may go through all the chapters of this tutorial step by step, or you may jump between chapters to learn specific things - it's really up to you.

Okay, let's get started with our very first PHP example, the standard Hello, world! With PHP, this is very easy. Be sure that you have installed Apache and PHP before using this example, or at least have access to a server with PHP capabilities. Have a look at the following example:

<?php
echo "Hello, world!";
?>

The <?php is important - it's your gate to the PHP interpreter. PHP documents can look just like ordinary HTML documents, and the PHP interpreter will ignore everything that's not within a set of the so-called PHP tags, which opens and ends our example. The echo construct simply outputs the string to the page. Try saving this with a .php extension and navigate to the page. If you're not sure how to do this, then have a look at one of the previous chapters about using the webserver. Once you call this page through the browser, the text "Hello, world!" will appear. We have just created our very first PHP page. In the next chapter, I will tell you a bit about the PHP tags that we just saw, since they are important to understand.


In the last chapter, we used those magic PHP tags. You may save your files with the .php extension, but that's not enough. Sure, when you use the appropriate extension, as defined in the config file of the webserver, PHP will look at the file. But only the stuff between the PHP tags are actually interpreted - the rest is just ignored. This allows you to mix HTML and PHP in the same file, and while other technologies like ASP.NET tries to separate code and markup, PHP still encourages this mix, and allows you to do it in several different ways.

In the previous chapter, we used the most common and most correct way of starting the PHP block:

<?php [code here] ?>

Another version is this one, which is the same kind of tags used for e.g. blocks of JavaScript code:

<script language="php"> [code here] </script>

Those two options are always available. However, a lot of PHP installations are set up to allow the short version as well:

<? [code here] ?>
Next 

No comments:

Post a Comment

RSS

Categories

Followers

Blog Archive

Php Introduction



PHP
 is an extremely popular, Open Source scripting language, most commonly used on webservers to produce dynamic pages. The name "PHP" is a recursive acronym for "PHP: Hypertext Preprocessor" and was initially created by Rasmus Lerdorf in 1994. As of today, the current version of PHP is version 5, with version 6 in the making.

As mentioned, PHP is mostly used on websites, which is what this tutorial will focus on. You may wish to set up your own test server, which is very easy to do, using the next couple of chapters to help you out. If you already have a server up and running, or at least access to a server running PHP 5, you can jump to one of the next sections, where we will start writing some PHP. You may go through all the chapters of this tutorial step by step, or you may jump between chapters to learn specific things - it's really up to you.

Okay, let's get started with our very first PHP example, the standard Hello, world! With PHP, this is very easy. Be sure that you have installed Apache and PHP before using this example, or at least have access to a server with PHP capabilities. Have a look at the following example:

<?php
echo "Hello, world!";
?>

The <?php is important - it's your gate to the PHP interpreter. PHP documents can look just like ordinary HTML documents, and the PHP interpreter will ignore everything that's not within a set of the so-called PHP tags, which opens and ends our example. The echo construct simply outputs the string to the page. Try saving this with a .php extension and navigate to the page. If you're not sure how to do this, then have a look at one of the previous chapters about using the webserver. Once you call this page through the browser, the text "Hello, world!" will appear. We have just created our very first PHP page. In the next chapter, I will tell you a bit about the PHP tags that we just saw, since they are important to understand.


In the last chapter, we used those magic PHP tags. You may save your files with the .php extension, but that's not enough. Sure, when you use the appropriate extension, as defined in the config file of the webserver, PHP will look at the file. But only the stuff between the PHP tags are actually interpreted - the rest is just ignored. This allows you to mix HTML and PHP in the same file, and while other technologies like ASP.NET tries to separate code and markup, PHP still encourages this mix, and allows you to do it in several different ways.

In the previous chapter, we used the most common and most correct way of starting the PHP block:

<?php [code here] ?>

Another version is this one, which is the same kind of tags used for e.g. blocks of JavaScript code:

<script language="php"> [code here] </script>

Those two options are always available. However, a lot of PHP installations are set up to allow the short version as well:

<? [code here] ?>
Next 

No comments:

Post a Comment