Hi, I'm looking for exercises that will help me to learn php (complex loops, arrays, tricks etc)
Everything else you should learn while doing something. Choose something you want to create and learn php along the way.
I follow the 'learn by doing' mentality - choose a project and work on it.
Here's a list of small (to medium) projects to try.
List files in a directory
Create a CLI-run and a web-interface tool to list files in directories. Also try navigating the sub-directories and returning information about files (or even showing the contents of them).
Good for traversing arrays and file information. Hints: glob
, FileInfo
.
Parse an XML file
Learn how to read parts of an XML file using SimpleXML. Very easy way to learn to use objects.
Create some dynamic images
A fun project you can do in an afternoon - display the current date and time on an image, or the viewer's hostname and IP. For extra credit create an object-oriented wrapper for GD (since PHP doesn't have one yet) that generates the image - and then extend it so that themes can be used.
Good for learning about GD, superglobals and object-oriented classes.
Build a (small) Twitter application
Use the Twitter API and cURL
to read data from the Twitter API (and even post things if you're adventurous). Learn to use other APIs as well (Digg's a good start).
Good for learning to use cURL
, web APIs and forms.
Build a notebook/todo list
Build a simple todo list application. A nice opportunity to practice some AJAX as well.
Build an image/file upload site
Make a simple site (like imageshack or rapidshare) that allows you to upload an image. Show the last 5 uploaded images below the form.
Hints: Handling file uploads, FileInfo.
Get friends to break your stuff
I think that the best way to initally learn about web security is to do so on a small, throw-away application, and reactively.
Get some knowledgeable friends to attack your application and seal vulnerabilities as they occur. Get them to help out if you're stuck and to review your security measures to see if you missed anything out. Some basics to learn about:
- SQL injection (easy to prevent, common flaw)
- XSS injection
- Scripting injection (never
eval
user input without extremely good reason!)
Create some sort of CMS
This can be as large or as small as you want it to be: a simple news reporting form to a personal blog. Make sure it includes user accounts and some sort of external user input (e.g. comments). Once you've got a basic system worked out try thinking about how it could be run by other people. Things to think about here:
- DAL (Database Access Layer - make it work on several database platforms)
- Templating
I highly recommend looking at other applications at this point. phpBB3 and vBulletin are good choices for PHP (phpBB is open source but vBulletin is a private product unfortunately). Some say Wordpress is a good thing to look at (I disagree) but I expect Joomla wouldn't be a bad place to look either.
Build a cacheable feed reader
Slightly more advanced - build a system that reads feeds, stores their contents and returns the data. Then work in caching to the system (e.g. store serialized data about feeds returned (since they won't be changed).
Good for learning about database interactivity and caching content. Hints: serialize (or even memcached).
Project Euler is language agnostic, but gives a set of problems to tackle while you learn the language.
The following page has15 Exercises for Learning a new Programming Language
Take a poem and:
- capitalize every vowel
- lower case every consonant
- list every other line
And another one:
Get the total number of days in a date range (i.e.: 2008-01-01 to 2011-06-23) without using any php date functions.
The easiest way to learn any language is not necessary to do with tutorials but rather use the language in an actual project. This means creating your own project if you have to and the logic required to accomplish such a project is what expands your php. This gives you the ability to think in PHP.......
e.g. 1)to test fundamentals...create a blog which allows users accounts and admin panel
2)to test email....create a mail listing which people can subscribe and get emails...
and etc.....I can only think of that for now....
We have just lauched a site with 26 PHP exercises, beginner to intermediate. It covers variables, control structures, forms, arrays and functions among other things. You start with the problem, then click a button to see the answer script code. Along with the answer script is a link to the output of the answer code. Come see at phpexercises.com.