Archive for March, 2004
Thu, 18 Mar 2004 9:24 UTC

Chris Shiflett announced the new PHPCommunity.org logo on his blog yesterday. Peter Jovanovic and Richard Davey are the winning artists.
No Comments
Permalink
Tags: php, php-community
Wed, 17 Mar 2004 12:14 UTC
I was hunting around today for a good RSS reader, when I found something called Pluck. It sounded interesting enough, so I decided to check it out. Boasting claims of no adware/spyware, I thought, “Well, maybe it’s okay.” Still, claims or no claims, I am always wary of freeware. Nonetheless, I wanted to see what it could do and whether it was what I wanted. In short, it wasn’t. It was a plugin for Microsoft Internet Explorer. This planted another seed in my head. “What if,” thought I, “Mozilla has such an extension for Firefox?” So, I proceeded to Mozilla.org.
I went to the extensions page for Firefox, where I found an RSS Reader Panel extension. It works great for what I wanted. I have now placed my entire blogroll into the panel, which pulls the RSS links from any specified bookmark folder. It also provides a Feedster search bar, and it can import and export OPML files. I’m thinking about exporting my OPML files regularly and importing them into my blogroll on this site. That way, I can keep both lists in sync.
No Comments
Permalink
Tags: firefox, mozilla, opml, pluck, rss-reader, sage
Fri, 12 Mar 2004 10:51 UTC
Many will be pleased to know that MySQL is drafting an exception to allow their GPL-licensed client libraries to be included in other FOSS applications.
Zak Greant relates the development of this exception in terms as a mother giving birth to her child. In fact, this child is a “savior” of sorts for those building an application under a FOSS license other than the GPL and wishing to include the MySQL Client libraries. It means that there is no longer a need to use the GPL on the overall application (as was the rule previous to this exception).
This is somewhat the reverse of a situation I spoke of earlier where you may include a GPL exception to include non-GPL libraries in an application. In this case, you would be including GPL libraries in a non-GPL application.
No Comments
Permalink
Tags: gnu, gpl, mysql
Tue, 9 Mar 2004 15:46 UTC
Since everyone and his brother has mentioned this on their blogs, I feel compelled to do the same. Yahoo! News posted an article on PHP 5. In all seriousness, it’s actually a good article and features quotes from PHP experts John Coggeshall and George Schlossnagle.
No Comments
Permalink
Tags: php, php5, yahoo
Mon, 8 Mar 2004 13:19 UTC
Today, I received an e-mail in response to my comments on Alison Overholt’s “The Google of E-mail?” from Ms. Overholt herself of Fast Company. She directed me to a page where she has posted several reader comments that she has received since her article went to press.
For the record, I did not say that Mozilla Thunderbird “has calendaring built in.” I said that it has a calendar extension available for users to install.
Alison Overholt’s article, The Google of E-mail? is now available on-line.
No Comments
Permalink
Tags: bloomba, mozilla, thunderbird
Sun, 7 Mar 2004 17:22 UTC
Today, I had the pleasure of meeting both Matt and Jeff face-to-face to talk about the formation of Atlanta PHP. We have a lot to accomplish before we finalize anything dealing with organizational structure, but we agreed that the Web site, a mission statement, and a mailing list are of utmost importance for starting. So, look for these features soon at atlphp.org.
Again, you may join us at #atlphp on Freenode IRC. I’ve also set up an Atlanta PHP community on Orkut. If you’re not a member, send me an e-mail and I’ll invite you.
No Comments
Permalink
Tags: atlphp, irc
Thu, 4 Mar 2004 16:03 UTC
Just a few moments ago, I heard some steps on my front porch. It was the mail carrier, and she left Chris Shiflett’s book HTTP Developer’s Handbook at my front door!
And, yesterday, the mail person came bearing Advanced PHP Programming, George Schlossnagle’s book. I’ll have plenty of reading to do over the next few days, and I plan on posting a review of each book. Look for it.
In then meantime, check out these books on your own. Browse to George’s and Chris’s blogs, and buy the books through their sites so that they get some extra commission from Amazon.
No Comments
Permalink
Tags: books
Tue, 2 Mar 2004 23:55 UTC
For those interested in Atlanta PHP, Matt has set up an IRC channel (#atlphp) on Freenode. We are working on getting some information up at the site (atlphp.org) and a mailing list once DNS issues are resolved. Until then, join us at #atlphp!
No Comments
Permalink
Tags: atlphp, irc, php
Tue, 2 Mar 2004 23:20 UTC
When relying on your end-user to supply information in the proper format, you’re S.O.L. when it comes to doing anything with that data. It’s best to use some proper PHP tools to validate your data and make sure it’s in a format your application can read before passing it along to other places. Follow me as I take a look at validating user-entered data in this first installment of what I hope to be a continuing series.
Most of the applications I work with have a Web-based front-end where users submit data. Other applications, also Web-based, involve data that has been imported from some other source, such as a text file. In both situations, the data that the application gathers is unreliable at best. I simply cannot trust a person or a text file (of data that was entered by a person) to enter data in the correct format that I require. In fact, since I’ve worked with text files that have been compiled from data entered by customer service reps, I’ve come to find that no two customer service reps enter data in the same way. In fact, most don’t enter data the same way twice!
Humans are unreliable. So, what is a programmer to do?
She must validate her data.
There are two places to validate data: the client-side and server-side. The client-side is a good choice since you’re able to check the data even as the user enters it, but you cannot rely on the user’s browser to work correctly. In fact, you cannot trust that there is a browser at all. Client-side validation may work for users who are following the proper means to enter data, but malicious hackers may send POST data through non-traditional means (not a browser). Thus, performing validation on the server-side adds an extra layer of security to your application. In short, don’t trust the user.
In this segment, I want to take a look at validating phone number data, and to valid phone numbers, we’ll be using regular expressions—or, more specifically, PCRE. There is another form of regular expression that PHP supports (POSIX extended), but I’m not going to touch on that at all. Consider POSIX extended regular expressions the weaker cousin of PCRE (I’ll likely be flamed for this). I feel that PCRE is very useful for many tasks, and you’ll see it turn up often when I talk about data validation.
The regular expression I’m using to validate phone numbers will take a US phone number and validate it according to almost any format in current use. This includes (555) 321-1234, 555-321-1234, 555 321-1234, 5553211234, 321-1234, and many more (even including formats with extensions). The expression looks like this:
/^[\(]?(\d{0,3})[\)]?[\s]?[\-]?(\d{3})[\s]?[\-]?(\d{4})[\s]?[x]?(\d*)$/
Wow! That’s Greek to me, says you. Indeed! Without turning this into a tutorial on the syntax of regular expressions, allow me to briefly examine each element of this expression.
/^ - asserts the beginning of data
[\(]? - 0 or 1 ('s
(\d{0,3}) - 0 to 3 numbers, the parentheses capture
the numbers [area code]
[\)]? - 0 or 1 )'s
[\s]? - 0 or 1 white space
[\-]? - 0 or 1 dash
(\d{3}) - exactly 3 numbers, captured [exchange]
[\s]? - 0 or 1 white space
[\-]? - 0 or 1 dash
(\d{4}) - exactly 4 numbers, captured [number]
[\s]? - 0 or 1 white space
[x]? - 0 or 1 "x"
(\d*) - 0 or more numbers, captured [extension]
$/ - asserts the end of data
Now that we have an expression that will work some magic and validate a phone number, let’s see how to put it into action.
Before we do that, though, let me digress and explain what’s going to happen in this validation process. We don’t just want to validate user input to ensure a user has entered a phone number in a proper format. If we wanted to do that, we could create three (or four) form fields (one for each element) and restrict the length of those fields. Then, on the server-side, we’d piece them together. The following method may still be used for that approach, but it is a powerful tool intended to validate phone numbers from sources that are well beyond control.
Take a text file of customer data from an electric utility, for example. I have no control over the phone number formats in the file, but I want to read the phone numbers, validate them against my regular expression, and break them up them into their individual components (area code, exchange, number, and extension). Once that’s done, I can put them back together in a unified format for entry into a database.
Here’s how to use the regular expression to do just that:
<?php
$phone_number = '(555) 321-1234';
$pattern =
'/^[\(]?(\d{0,3})[\)]?[\s]?[\-]?(\d{3})[\s]?[\-]?(\d{4})[\s]?[x]?(\d*)$/';
if (preg_match($pattern, $phone_number, $matches))
{
$phone_number = $matches[0];
$area_code = $matches[1];
$exchange = $matches[2];
$number = $matches[3];
$extension = $matches[4];
}
?>
Since $phone_number matches the pattern, preg_match() will return true. When preg_match() is true, it will pull those elements matched in the parentheses and place them into $matches, an array of the sub-pattern matches. The code listing shows what each element of the array stores. In the example, we would have the following result:
$phone_number = "(555) 321-1234"
$area_code = "555"
$exchange = "321"
$number = "1234"
$extension = empty
If $phone_number is “321-1234” without the area code, then $area_code will be blank. If the number is ”(555) 321-1234×4321,” then $extension will be “4321.” Go ahead and try the code with any US formatted number you can think of. I’m fairly certain it will work. If not, let me know; I’m always willing to revise my code.
So, the pattern matches certain elements in the phone number and separates them. You can now take each of these elements and format the number as you wish so that all the numbers in the database will follow the same pattern. Likewise, you could have a free form field—rather than three separate fields—on a Web page for users to enter a phone number. This code could validate that number and parse it for your application to use.
Validating information is an often overlooked, but essential, part of Web development. It is crucial to the integrity of data and to the security of an application to validate any input. I believe that most pass off validation out of laziness, but, as you can see, validating a phone number only adds a few extra lines of code to your application. Wrap this up in a reusable function, and you have something in your PHP toolkit that can be used over and over again with ease.
Related Web sites:
No Comments
Permalink
Tags: filter-input, pcre, phone-numbers, php, regular-expressions
Mon, 1 Mar 2004 19:25 UTC
Since the news of PHPCommunity.org reached me and I was connected to the New York PHP Web site through Chris Shiflett’s site, I have been toying with the idea of starting a PHP group in Atlanta (Georgia). It strikes me as odd that there isn’t already one.
I’ve done some Google searching and haven’t found any such group. I would think that the Technology Association of Georgia would have some sort of SIG for PHP, but their direction and goals seem to have changed recently from a networking group that helps technology developers to a networking group that serves to inform businesses on technology. Still, they do not offer any information on open-source technologies. The closest they come is a Web Services working group.
So, today, while looking at nyphp.org, I decided to check on atlphp.org and see whether it is registered. In fact, it is. I did a WHOIS on it and saw that it was registered on February 27, a mere three days ago. I called the contact listed on the registration and left a message. At this point, I still wasn’t sure whether the site was meant as a PHP user group for Atlanta or something entirely unrelated (as domain names can often be—my friend registered XXXSexyLebians.com as a pointer to JoeyKratz.com—we thought it was so funny; I wonder how many people that ticks off!).
A few hours later, Matt Kern, the registrant for atlphp.org, called me back. Calming my fears, he told me that he and a few others registered the domain name as a precursor to forming the local user group for Atlanta. So, I volunteered to help in their efforts. Now I don’t have to go out and register something like atlantaphp.org, and I already know that there is an interest in this area. After speaking with Matt, I talked to Chris, who offered to put us in touch with Hans Zaunere, the founder and president of NYPHP. Hans, he said, could help offer advice on starting the group and inform us on problems and issues they faced in New York.
So, following on the heels of the excitement that the PHPCommunity.org announcement brought me is the soon-to-be-announced creation of a PHP user group in Atlanta. It is my hope that those in Atlanta will become involved in PHPCommunity.org, thus further uniting PHP developers around the world. And I intend to see to it that just that happens.
I hope Matt doesn’t get mad at me for announcing this on here. Announcements made in the PHP community seem to spread far and wide rather quickly and draw much attention (take the announcement of PHPCommunity.org on PHP.net, for example).
No Comments
Permalink
Tags: atlphp, nyphp, php, php-community