May 15, 2008
I was recently tasked with creating a simple dirty word filter in PHP that relies on our blacklist of about 600 words. The filter should simply replace the word with its character length in asterisks.
My first attempt just used str_replace, but I quickly realized that even dirty words embedded in clean words would […]
March 27, 2007
Following the code that I found here, I made a quick PHP4 class that creates a single sheet Excel file. The class has a download() function that will send the appropriate headers for a binary download.
March 20, 2007
function leadingZeros($num,$numDigits) {
return sprintf("%0".$numDigits."d",$num);
}
echo leadingZeros(1,2); // 01
echo leadingZeros(11,2); // 11
echo leadingZeros(11,1); // 11
echo leadingZeros(253,4); // 0253
According to a post on the PHP.net page for str_pad(), sprintf() is much faster for this purpose.