At 04:08 AM 2/10/2006, Dave Jarvis wrote:
It is a collection of six simple tricks I use to give websites that
extra flair of functionality.
http://joot.com/dave/writings/articles/php-examples.shtml
I hope you find the auto-complete city and country is especially useful.
Nice collection, Dave. I've got a few comments:
Why don't you make the table of contents at the top of the page a
list of links for easier navigation?
XML Tag Parsing:
Your code assumes that the tag you're searching for is unique and
doesn't have any attributes. I'd think you'd want to use RegExp to
search for something like this:
<$tag( [^>]*)*>
= tagName followed by (zero or more groups of [a space followed by
any number of characters that aren't a close-bracket]) followed by a
close-bracket [1]
cf: PCRE regex pattern syntax
http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
If you use preg_match() you can capture multiple instances of the tag
and not just the first one.
cf: preg_match()
http://au.php.net/preg_match
Auto-complete City & Country:
These function references are undefined -- deliberately?
get_location_xml()
parse_city()
parse_country()
I have some suggestions for your country <select> list:
a) For greater compatibility with future markup (XHTML etc.) I
suggest you change:
SELECTED='true'
to:
selected="selected"
b) Your exhaustive list of if-tests is quite verbose and could be
shrunk. For example, you could throw the country abbreviations &
names into an array and then walk the array outputting the select
options, including the "selected" attribute when there's a match with
the target country.
c) You're mixing PHP logic with HTML markup more than is
necessary. Even including both in the same script you could separate
them something like this:
______________________
$aNations = array("AU"=>"Australia", "CA"=>"Canada", ...);
$sSelectedAttr = " selected=\"selected\"";
foreach ($aNations as $sNA => $sNation)
{
$sSelected = (($country == $sNA) ? $sSelectedAttr : "");
echo <<< heredocNationOption
<option value="$sNA"$sSelected>$sNation</option>
heredocNationOption;
}
______________________
Performing the logic and outputting the markup as separate steps is
my personal preference simply because it tends to make the code
easier to modify in future. More ideally, I'd remove the literal
markup from the function entirely, passing it as template argument,
and even further removing the markup completely from the PHP script
to a separate template file, so that the user (developer) can tweak
the markup independently of messing with the logic. For example, if
you pass the markup to the function as arguments (listBegin,
listOption, listSelected, and listEnd) then you can output the list
as a SELECT, OL, UL, TABLE, etc. without having to modify the script.
Regards,
Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php