I was asked to day to make a little writeup of how to get into PHP, one of my favorite languages. PHP is easy to jump into and it offers amazing opportunities to expand beyond basic HTML and CSS. I normally post about specific features or functions of PHP, but this time, for a friend, I’m writing a special post.
Using HTML and CSS can only make your website so useful. Just those two things are static. In other words, they never change. Once you write the HTML, it stays the same until you, the coder, changes it. That is why it is only so useful. In order to make your website more interesting and generally serve a purpose beyond justÃ‚Â providingÃ‚Â information, you can use PHP.
PHP is a server side scripting language. PHP doesn’t really stand for anything anymore, originally it was supposed to mean Hypertext Pre-Processor. So what does it do? It allows you to make your site interactive. For example, you could have an html-form on your page and with it, you can ask the user to register to your site. Then you could make only registered users see specific content. PHP can handle that for you easily.
PHP is generally installed on most linux distributions and also Ã‚Â OS 10.5 however for Windows, you’ll have to download Apache, PHP and Mysql. Using xampp is probably the best solution for aÃ‚Â newcomerÃ‚Â to web scripting. xampp is a little server package that contains Apache, PHP and Mysql all in one plus a neat little interface. You can download xampp from the apachefriends website. Setting it up is easy too. It is just a generic windows installer and it doesn’t ask for much if any input, aside from the installation directory. Generally, on Windows, people prefer to pick a top level directory like C:\xampp\. When you see a list of options like Start Menu and Service Section, make sure you leave it as is. The defaults serve our purposes perfectly. Once it is done, you’ll have a folder in C and an icon on the desktop. You should click the Start Xampp icon and open the manager up. Start both Apache and Mysql. Whenever you want to work with PHP, make sure both of things are started up. Then you can minimize it to go to a tasktray icon.
Now, here is the tough part. Go to the directory you put xampp in, probably the default C:\xampp\ folder and inside of it, look for another folder called htdocs. Open it up and then right click in the blank space and go to new, then new text document. This makes a new file so you can start coding. Before you start though, you need to make sure you have file extensions turned on (you can read this tutorial on how to turn file exentsions on). When see the .txt extension at the end of the file you just created, you’re ready to proceed. Rename the file something like, testing.php. Once you do that, open your php file in your favorite text editor. You can use notepad but it isn’t that great. Try some of my favorites, PSPad or Notepad++. Once you see your empty file in your text editor, continue.
The final challenge of this introduction is actually adding some code to your file. Basically, I’m going to give you the code to print out a single line with PHP. After that, you can check out other tutorials on more aspects.
<?php echo("hello world!"); ?>
This simply prints hello world to the screen and that is it. And yes, you really do need those question marks there.