Introduction

The page has been translated into Serbo-Croatian by Jovana Milutinovich from Webhostinggeeks.com.

PHP stands for “PHP: Hypertext Pre-processor”. The funny abbreviation follows the style set by Richard Stallmann when he founded GNU: GNU’s not Unix! As the name says, it’s a pre-processor for hypertext, which is just another word for what most people call webpages. Since it’s a preprocessor, it runs on the remote web server and processes the webpages before they are sent to the browser. This makes it a so-called server-side scripting language. The fact that it runs on the server has several benefits, and some drawbacks. Let’s take the benefits first:

  • On the server you can have access to things like a database. This means that you can make a script that sorts through large amounts of data, without the client having to download them first.

  • It’s only the output from the script that is sent to the client, not the script itself. That means that you can make the script invisible from the end-user. That makes PHP-scripts browser-neutral; they don’t depend on some capability of the browser. It also means that you don’t have to worry that someone else can steal your carefully crafted script. It’s not like when you make a JavaScript — everybody is able to read it in the source of the webpage. It has to be this way with client-side scripting, or else the client would be unable to get the source of the script, and therefore unable to do any scripting.

  • You can make your own programs for use in your scripts. You could implement part of the script in C, and then call the program from your script to make it run faster. PHP is a parsed language, meaning that there are no compiled binaries. Every time someone requests a page with PHP-code, the parser looks through the page and executes any PHP-statements it might find. Fortunately this is a very fast process, but you might want to speed things up if you have a very complicated script.

    When you make a C-program, you compile the source and then run the resulting binary. This makes PHP slower than an equivalent C-program.

As I said, there are also some drawbacks:

  • By executing everything on the server, you put more strain on it. With many concurrent requests, and large complex scripts, the server might not be able to handle it. But this isn’t a real concern because the parser in PHP is so quick. And if your server still can’t cope with the number of visitors, then you should be able to generate some revenue from banners on your site, and then pay for a bigger server :-)

  • The pages can’t do anything themselves — you need the server to do the magic. This means that the pages will lose some of their functionality if your visitors decide to save them to their computer.

    You could of course still put some JavaScript in your pages. This is a very powerful combination between server- and client-side scripting. You could use PHP to fetch some values from a database, and then setup your variables in the JavaScript with these values.

In my opinion the benefits clearly outweigh the drawbacks — that’s the reason I’m using PHP :-). And I’m not the only one — an increasing number of websites are using PHP.

Some Background Information

PHP is actually a rather simple language, despite its great powers. It’s a young language, so the developers have had the chance to learn from previous language’s mistakes and implement their strengths. Much of the syntax is borrowed from C. This is reflected in the different conditional statements, the loop-structures, the boolean operators, and the assignment of variables. Since C is probably the most common programming language today, this should make PHP easy to pick up. Even if you don’t have any previous experience with C you should be able to learn it quickly.

Another thing that makes PHP easy to learn is it’s relaxed way of dealing with the types of variables. Its very simple: you don’t have to think of the types of variables at all! If you assign a number to a variable, then it just works. When you later try to output the variable to the browser it also just works. PHP takes care of converting the variable from an integer-type to a string-type, on the fly and automatically. To make matters even simpler, you don’t even declare your variables — you just assign a value to them, and then they are ready. If you are an experienced programmer (and especially if you normally program in strongly-typed language such as Pascal) you might say: “This can’t be real! There’s no syntax in this language. When you just declare variables like that you don’t have any control — you don’t even know what type a variable is!” All I can say to this is: It really doesn’t matter — most of the time you’re interested in the value of the variable, not its type. And if you really want, then you can indeed find out what type a given variable is. It could come in handy if you want to check to see if a parameter to a function really is of a given type.

Because PHP is meant to be used with webpages it has a lot of functions to deal with text so that you can get your work done quickly and efficiently. Because of that most of the built-in functions are simple and straightforward to use.

Being web-oriented, PHP also contains all the functions you’ll need to do things on the Internet. There are functions for connecting to remote webservers, checking mail via POP3 or IMAP, or url encoding strings to protect special characters.

Together with a good manual, you have all the help you’ll need. And if you get stuck — then you can count on the community. There has been a lot written about PHP on the net (you are reading just such a thing now :-) and there’s countless mailings-lists you can subscribe to.

Installation

Please refer to the installation instructions given in the PHP manual.

Now you have hopefully installed PHP, and you’ve been told about how easy it is, and how many things you can do with it. Let’s see it in action then!

19 Comments

  1. raghuprasad:

    I am an employee of an organisation, where i work on computer. I want to learn PHP and want to do something using php. I don’t have any programing skills and also I am new to the PHP. I find your tutorial very user-friendly. Can you please tell me to practice php, do I need a separate server or can I install it on my PC itself and work on it?

    My primary objective is to develop some web pages and then to work further in that.

    Regards,
    Raghuprasad.

  2. Martin Geisler:

    You can install PHP on your own computer without problems. For that you’ll need Apache and of course PHP. There are several installation tool out there that will install Apache + PHP + MySQL for you under Windows, giving you a so-called WAMP server. (For Linux the same combination is often called LAMP.)

    Please try these links:

    I have no idea of what quality those projects are since I only use Linux, but try them out or search the net for more.

  3. Viper:

    Awesome work Martin. This is helping me very much. I am pretty new to PHP, so this booklet helped me much. Also, instead of reading the entire then, I jotted down every single main pointer, so instead of reading for an hour, I only had to read for 25mins.

    THANKS!

  4. Viper:

    Oh yeah, I forgot to mention, would you mind if I put my shorter form guide on my computer forum?

  5. Martin Geisler:

    No, of course not! Especially if you link back to my tutorial :-)

  6. Viper:

    Ok, thanks.

    It looks a lot like your tutorial, but I changed a few stuff so that it didn’t take as long to read.

    I also linked back to this intro page!

  7. Martin Geisler:

    Nice, thank you very much!

  8. Terry:

    In the tutorial/introduction page you have an error in your grammar. Just thought I’d let you know since it’s the only one I’ve found so far. Very good! You say:
    ‘Because PHP is meant to be used with webpages it has a lot of functions to deal with text. Generally you can say that PHP is specially designed to deal with webpages, and doing so quickly and efficiently. Because of that most of the built-in functions are simple and straightforward to use.’
    Where you say ‘doing so’ don’t you mean ‘do so’?
    Heh-
    –I’m going to learn a lot here. I am already impressed. You watch. I’ll show you my program when it’s done! Thanks for doing this!!
    Terry

  9. Martin Geisler:

    Thanks for the notice! I’ve updated the page a bit, I hope it’s better now.

  10. Ben:

    Hey Martin,

    Just thought I’d drop you a line to say this is a cool and informative little blog you’ve got set up here. The last few days I’ve installed and configured PHP, MySQL and Apache on Windows XP and created a webpage for a project I’m working on. Thanks to this easy to follow introduction, I’m able to hit the ground running with PHP without much of a delay between finishing the html/css for the site and jumping straight into the mysql/PHP work - other sites out there arent quite so clean and focused - taking it a while to read through different peoples articles which dont quite tie in with each other - so good work.

    I’d love to see a few more in depth articles on more complex stuff if you have the time. Maybe even some sample code for people to play with - giving the site an extra dimension and making it more interactive.

    I look forward to reading more of your articles - if you have have the time!

    Ben

  11. Martin Geisler:

    Thanks for the comments, I’m very glad you like my little site.

    You’re right about the time — that’s the limiting factor. I’ve sort of shifted my focus over to different projects instead of writing guides for my site. Those projects are PEL and PHP Shell which feature real-life code. I guess the code there is somewhat complicated, but maybe you would like to look at the edit-description.php file from PEL anyway since it is heavely commented. It uses functions, objects, and lots of builtin PHP functions.

  12. Ben:

    Little wasn’t meant in a belittling term btw :) Just that it’s not massive/cluttered and poorly managed, like a fair few other sites I’ve seen about. It’s great that you also take the time to promptly reply to people :)

    edit-description.php’s code is absolutely great for a begginer. I can understand the lack of time - it’s difficult to keep a life whilst working overtime to meet deadlines, writing your own personal programs/running a site - and most importantly actually having a life. Looks like you’re doing an awesome job - kudos :)

  13. Martin Geisler:

    Thanks again for your encouraging comments, I appreciate it!

  14. Sourabh:

    Hello Martin, I have started reading your blog for PHP.I liked the introduction.I just have some confusion regarding the installation of apacher and php.

    It seems to be that it is free.

    I am using windows XP as my OS, can i start learning php on it, directly downlaoding WAMP on my computer?

    Please clarify.

    Regards,
    Sourabh.

  15. Martin Geisler:

    Hi Sourabh,

    I don’t use Windows and for GNU/Linux I always install PHP using Debian packages… So I cannot help you with the installation — please seek help somewhere else. The links above should give you plenty of information.

  16. Rob Escobar:

    I have hads some issues attempting PHP

    However I hope to get better.

    Duke

  17. tokz:

    good work..thank you for the information..

  18. Satish Chandra A. P. (Bangalore):

    Hello Martin,
    First i really wish god to bless you. You have described PHP in a simple way so that anybody can understand it. Today itself i started to learn about PHP and after doing research in Google which site to start selected yours. Second thing more than windows i love linux very much. I use Fedora 9 and windows XP in my home and want to install in both. Second in office i am using Mandriva in office and i am a user and don’t have the root password. Can i able to install being a user without having root password. Also how to do the same thing in Fedora 9 so that i can install at my home desktop.

  19. barisi:

    i am in programming and php, i want to know how to use php to design website. want and want do i need.

Leave a comment