ITT #16: Create a Template Parsing System with PHP
One of my most recent obsessions has been with simplifying my custom CMS to
allow me to generate full sites without changing anything but HTML
template files and a basic configuration file. In this week's Instant Tip Tuesday, we'll explore
one of the ways we can dynamically generate output and wrap it in a
template file.
NOTE: This is a proof-of-concept type of thing, not a
production-ready script. Be aware that I haven't used a script like this on
a real site, and therefore have no idea if it's fast, effective, or even
useful. For now, this is just a "hey, cool!" sort of thing; use with
discretion.
Download the Files
So, What Are We Trying to Do?
To try and explain what our goal is...
read more
ITT #15: Create a Simple Contact Form
NOTE: This entry has been improved upon by adding spam
protection and sessions. It's strongly recommended that you use the newer version of the
simple contact form.
Making yourself accessible is one of the most important aspects of a site
that aims to connect with its audience online, and nothing makes a person
more accessible than an easy-to-use contact form.
In this week's Instant Tip
Tuesday, we'll build a simple (less than 200 lines of code, including
comments) contact form that will allow users to contact us without needing
to open their mail client or copy and paste our email address into their
web mail service. Our finished contact form will do the following:
- Accept the user's name, email, URL, and a message
- Verify that required fields were filled out
- Validate...
read more
ITT #14: Optimizing MySQL Queries
DISCLAIMER: I am by no means a MySQL optimization expert, and I can't guarantee that the information provided in this blog entry will take a query from painfully slow to blazing fast. I can, however, guarantee that this entry was written with the best intentions and aims to explore some of the more advanced features of MySQL.
This week, I wanted to share some of my recent experiments with MySQL queries in regard to lowering the number of requests sent to the database server and, hopefully, avoiding the bottleneck that can form on sites that rely heavily on database interaction.
What Are MySQL Joins?
A JOIN in MySQL is a tool that allows developers to combine one or more tables in a query. There are a few flavors... read moreITT #13: Build a Menu with Recursive Functions
To continue my recent obsession with array handling, I want to spend this week talking about recursive functions and their application in dealing with arrays.
The goal of our exercise today is to build a menu, complete with sub-menu, all based off one function that runs recursively.
What Is Recursion? In computer science, recursion is a concept in which a function can call itself. This is similar to the idea of looping in PHP, but it provides an opportunity, in the case of array handling, to add more fine-grain control into a program.
On a basic level, recursion can be illustrated with the following code:
function plusOne($x) { if($x<10) { echo ++$x, "<br />"; plusOne($x); } else { echo 'Finished! <br />'; } } Calling this function will result in the following output:
1 2 3 4 5 6 7 8 9 10 Finished! Obviously, the above could have been accomplished very simply with a loop... read more