Unfortunately, I'm spending the majority of my awake time actually working on PHP code, but very little of it I can actually share here, because almost none of it makes sense out of context. However, I wanted to pass along a few bits I've collected that can stand on their own, and might be useful as reference bits for other people.
So, a few variously-nifty PHP functions.
Pulling the first x words from a text string
function firstwords($str,$wordcount) {
# Gareth (omnipotent.net) 0wnz m3.
# Someday, I will be able to do this sort of thing when I grow up.
$words=preg_split('/([\s.,;]+)/',$str,$wordcount+1,PREG_SPLIT_DELIM_CAPTURE);
array_pop($words);
return(implode(",$words));
}
The issue – most existing "pull first words" functions are pretty brain-dead; they don't always take punctuation into account. This one does.
Testing a string to see if it is alphanumeric
function is_alphanumeric($test) {
return (preg_match("/^[a-z0-9 ]+$/i", $test));
}
Testing a string to see if it is a valid email address
function valid_email($email) {
# thanks again, Gareth – omnipotent.net
$host = substr($weenie,strpos($weenie,"@") + 1);
if (eregi("^([[:alnum:]_%+=.-]+)@([[:alnum:]_.-]+)\.([a-z]{2,3}|[0-9]{1,3})$",$weenie)
&& (checkdnsrr($host,"MX") || checkdnsrr($host,"A"))) {
return 1;
} else {
return 0;
}
}
Most people forget to test things like the wacky compuserve emails. My lovely sysadmin, Gareth, gave me this function. It checks that, as well as checking the machine name for validity. Obsessive? Only a little… But extremely useful nonetheless.
Random password generator
I rather like the one available at befriend.com and have been using it on quarto.
The rest really doesn't make sense out of context…but let's just say that SQL and PHP and I have been getting mighty, mighty cozy lately. I feel pretty bad about not being able to contribute code here, so if you have questions in those realms…ask! Please! I'd feel better!