HomePostsNov 20, 2008

Beginner Exercises to Learn PHP Programming

I’ve been on a quest to try my hand at a real programming language. I get the feeling that I’m really going to like what I learn. Said another way, I really hope that I like what I learn. My brain kind of works like a computer and if I can just figure out how a computer operates on the nano level, I’ll be one step closer to understanding myself.

That was a joke.

After a thoroughly non-exhaustive consideration of available languages, I chose PHP to learn a few things. Since I’ve been doing work in WordPress (written in PHP) and have had a few people express the need for database functionality in their webpages (PHP and MySQL can handle almost anything you can throw at it) AND I’m working on a site based on Pligg (also written in PHP), it seemed like the right direction to go. It also seems fairly simple to pick up (comparatively) and the support/community/documentation is quite robust (one of the few words I use despite the fact that I hate it).

Despite the many pages dedicated to PHP tutorials, how-tos, and tips/tricks, I have not been very successful finding exercises I can practice with. I’ve been a student for longer than I care to admit, I need homework to function properly!! So I searched high and low and put together this list of beginner PHP exercises. I’m also including a link to my results so people can see the results (no guarantee of accuracy).

From the Digital Point forums

  1. Define a variable called ‘name’ containing the text ‘Mario’ and then write “I am Mario.” using the variable to write the ‘Mario’ part. You may only use two commands max!
  2. Use the code from the previous example but add a check using an ‘if’ condition to check whether the name is ‘mario’. Place the text from the previous example in the ‘if’ condition.
  3. Try changing the $name variable to ‘awaken’. You’ll notice that the previous script writes nothing (If it doesn’t, go back and redo #2, it’s not complete!)
  4. Use a while-loop that starts at 0 and keeps running while the number is lower then 5. Write the variable to the screen after each run.
  5. Modify the previous example to use a ‘for’ loop instead of a ‘while’ loop

From Huzilla.org’s PHP book

A quick note about this site. The “book” is very useful but on every page you’ll see a big headline that tells you that that particular version in not the most current. The current version took a minute to load and was in wiki format. I didn’t immediately see any of the quizzes or exercises so I’m linking to the old version.

I’m only listing the first few sections of quizzes (the beginner information). Each section listed in the table of contents [http://www.hudzilla.org/phpbook/index.php] has its own exercise bank. URL links have been removed because their server is terribly slow at times and times out occasionally. Keep trying, it’s there (unless you get a 404).

From Iowa State University

“Download the yeast.txt file from the website. Write a script that displays the names of all the protein-fragments contained in the file [the block of capital letters only].

“Adapt [the script above] to construct an array while you read through the file that contains all the titles of fragments. Now encapsulate that functionality in a PHP function GetFragmentTitles($fn) whereby $fn is name of the file and the return result is an array containing all the titles. The pseudocode for this function is as follows:

function GetFragmentTitles($fn) {
// open file $fn
// create a new array $titles
// for each $line in file $fn
// if $line represents a title
// add the title to array
// close the file
return $titles;

“Construct a form where the end-user can enter (part of) the name of a fragment. A second script subsequently searches the titles to see if (part of) the name occurs in the file. Report on how many fragments are found.

“Simulate a BLAST-search interface: a user can enter part of a sequence and your script should report if and where the subsequence is found. Use really small fragments to see if they show up multiple times. What do you report if no fragments are found?

W3 Schools PHP Quiz

< Take Action >

Suggest changes on GitHub ›

Comment via:

Email › GitHub ›

Subscribe via:
RSS › Twitter › GitHub ›

< Read More >

Software Engineering

Nov 24, 2008

My New ASUS EEE 1000H (or) How my life just got a whole lot more productive

I’m not the type of person who needs new, cool things all the time. But one device recently has changed what I do so drastically that it’s my obligation to talk about it.


Nov 07, 2008

The Worst Possible Way to Work (or) How to Find a System That Works for You

I’m going to share with you how I work. This method would/will drive certain people nuts. This method is not foolproof but none of them are.