Computer Magic
Software Design Just For You
 
 



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:

  • Variables – These are just places to hold information like your name or age. These are temporary locations in that they exist in memory and not on your hard drive so if the program ends or the computer is shut off, this information will go away. We use them because they are FAST when compaired to a hard drive.
  • Functions and/or Subroutines – Think about a mathmatical function like F(x). You simply pass in a value, and it returns an answer. In programming, functions work the same way, only they don’t have to be mathmatical. This allows you to write function once (e.g. to calculate the square root) and use it in multiple places without having to re-write the code each time.
    Subroutines are like functions except that they don’t return an answer.
  • Classes and Objects – OOP (Object Oriented Programming) is a great tool that allows programmers to write reusable code and simplify an applications interface. We will get into this more later. It is VERY usefull and when used correctly, can reduce the number of bugs, lines of code, and even make a program more efficient (when used correctly!).
  • I/O – Input Output. Every program needs to gather information (from the keyboard, form a file, from the network) and then output its answers in a usable way (computer screen, network, to a file). Most applications today use a GUI (Graphical User Interface). This GUI helps aid the programmer in presenting a uniform and easy to use interface for the user. This is one type of I/O system. Another type is to create a config file where the application can read this information and know how to react accordingly (start -> run -> win.ini -> click ok). Along with this you could have an output file that would hold the results. There are many combinations and options available to mix and match. One option we will work heavily with will be databases.
  • 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

    Comments are closed.


    Home | My Blog | Products | Edumed | About Us | Portfolio | Services | Location | Contact Us | Embedded Python | College Courses | Quick Scan | Web Spy | EZ Auction | Web Hosting
    This page has been viewed 827295 times.

    Copyright © 2005 Computer Magic And Software Design
    (360) 417-6844
    computermagic@hotmail.com
    computer magic