PHP: Introduction To
Posted October 21, 2006on:
PHP is a great language for beginners and advanced programmers all alike (especially with v. 5). Like other scripting languages, it is compiled at run time, so there is no extra work on the developers part before running the code.
First off, where do you write PHP? Well, you can write PHP in any text editor. If you like to use a specific program to write HTML, you can use that same application to write PHP. You start a block of code with “<?php” and end it with “?>”. Pretty easy huh? Here’s a sample that will output “Hello World!”:
echo “Hello World!”;
You can put this code in any HTML page and save it with a .php extension. Upload it to your web host (assuming they offer PHP) and access it just like you would any HTML file. You should see “Hello World!” in the place of the code.
All that’s happening here is a single statement. We are using the echo function to output data to the browser. Echo will output whatever you put after it, in this case, we used text. If you’re new to programming you should start getting used to calling text a string (because it’s a string of characters). That’s what we call text in programming, so getting that down to start is helpful.
PHP can be used for a variety of things. It can build images on the fly and output them, handle forms, insert and retrieve information from a database, talk to other applications, access other websites, send email, and much more!
Next we’ll go more into actually using the language!