UltraMega Blog

Easy Text Validation Without Regular Expressions

Filtering data from user input and other external sources is the most important part of writing secure code, but it's also handy to make sure users supply the correct type of info to a registration form for example. Sometimes it's simply making sure something is a number or of a certain length, but other times it's something that follows a specific pattern (like an email address). This used to be a job for complex regular expressions, but fortunately, there is an easier and more reliable solution.

PHP 5.2.0 and up comes with a very convenient set of data filtering functions. These functions allow you to easily validate common things such as emails and URLs, that would otherwise require complex regular expressions that don't always work. This tutorial will focus on the simplest function filter_var().


Creating a TinyURL Clone

This tutorial will explain how to create a basic clone of the TinyURL service. If you've never heard of it, TinyURL allows you to turn long URLs into shorter links so they can be easily sent via email or other means. It might be fun to create your own personalized version that works just as well, and it's very easy to do. We'll go over the database structure, creating the required PHP script, and using mod_rewrite to make nicer URLs.


Working With Directories in PHP

PHP offers some built in file system related functions that allow you to work directly with files and directories. This tutorial will focus on working with directories. It will explain how to open and list the contents of directories, which is actually pretty easy to do.

The process goes pretty much like this: open a directory, read the directory in a loop, check each entry to see if it is a file or directory, display each accordingly, then close the directory.