[ View menu ]

Archive for 'web development'

Replacing whole words in strings in PHP

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 […]

PHP Excel Export class

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.

Adding keyword and description meta tags to Gallery2

The File
Find the template.tpl file for your current theme. I found mine here:
gallery2/themes/matrix/templates/template.tpl

Adding leading zeros in PHP

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.

Viewing your site before domain propagation

March 19, 2007

So you just bought a new domain name and/or a new host and you want to see everything in action, but you can’t yet because your domain hasn’t propagated! Luckily, there’s an easy way to temporarily jump forward in time.
The quickest and easiest work-around is to just edit your hosts file so that your […]

min-height for Internet Explorer

March 14, 2007

Here’s my favorite, easy work-around for the lack of min-height support in Internet Explorer 6.0:

XHTML 1.0 Strict template

December 12, 2006

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
 
</body>
</html>

Netflix Queue Randomizer

November 16, 2006

12/28/06 Update: Joseph Miller updated the script with a feature that keeps series in order. Check out his script here. Thanks Joseph!
I didn’t want to install Grease Monkey, and none of the other scripts worked too well so I wrote my own.

HTML 4.01 Strict template

October 5, 2006

I find that I look for this starting template A LOT. HTML-Kit has a template for HTML 4.01 Strict when you create a new HTML file, but I use Notepad++ for most of my editing now, so I need to dig up this code all the time.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>