PHP Tutorial – Lession 1 What is programming?
Good Morning,
Learning to write software is tough. Not because it is actually hard, but because it requires LOTS of patience and time. More than many people are willing to spend. Aditionally, programming works like math, you can’t learn by watching, you need to get your hands dirty!
Lets talk about the components of a program. When you write software, you simply tell the computer what to do. The hard part is that the computer takes you so literally. Imagine trying to tell a two year old to take a bath. If you tell them, they might turn on the water, but never plug the tub. They may fill the tub, but never take off their clothes. They may even forget to use soap or get in. You have to be very specific with them and guide them through the process. Computers are the same way, but with out the cute that is generally present with a young child. In that case, its probly more like trying to talk Forest Gump through the process of disarming a nuclear bomb over the phone. It isn’t pretty, but it can be done if you can step outside your own little world and think they way he does.
Some of the parts that make up a program are:
Subroutines are like functions except that they don’t return an answer.
Thats a good start. Lets try an actual program. Because we are using PHP, you will need a server setup where you can upload PHP scripts. The PHP scripts actually run on a server and if viewed locally will just show a text file full of code. If you need web space, you can contact me for prices.
Here is the actual program…
<?php print "PHP Rocks!!!"; ?>
This snippet of code should output “PHP Rocks!!!” to your browser window if it works correctly. If you see the whole file (including the php tags) then your server isn’t executing the PHP code correctly. The cool thing about PHP is that ONLY THE OUTPUT goes to the web browser keeping your code safe!
Lets break this down a bit. The first line (the php tag) tells PHP that actual code follows. This allows you to put PHP code into an HTML file without anyone getting confused as to where HTML stops and PHP starts.
The last line (the closing php tag or ?>) is the signal that the stuff after this should be treated like HTML again.
The middle line calls the print function which simply sends the specified output to the screen (or web browser in this case). The ; at the end tells PHP that this line is done. Give it a try. Your assignment is to save that as a file called hw.php and put it on a server, then send me a URL where I can navigate and see your handy work.
Ray Pulsipher
Owner
Computer Magic And Software Design