Archive for June, 2006

I just came across a really odd error while matching for some specific characters in PHP. I found the error while using both preg_match() and ereg().

With preg, the error was this:
Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 11 in /temp.php on line 5

With ereg, the error was this:
Warning: ereg() [function.ereg]: REG_ERANGE in temp.php on line 13

Both were caused by the same error or bug. I’m not sure which.

Here is the bad code:
$userid = 'abcDEF_-.';
if(preg_match('/[^a-zA-Z0-9_-\.]/', $userid)) {
echo 'bad';
} else {
echo 'good';
}
 
if (ereg("[^a-zA-Z0-9_-.]", $userid)) {
echo 'bad';
} else {
echo 'good';
}

That all seems correct, doesn’t it? It is checking to see if the userid has something other than those characters.

The problem? The dash, or hyphen, being before the period. It thinks it’s a range, like you see in a-z. This may not be a bug, per se, but it’s certainly not smart enough for me.

The solution? Simply put the dash at the end of the regex.

$userid = 'abcDEF_-.';
if(preg_match('/[^a-zA-Z0-9_\.-]/', $userid)) {
echo 'bad';
} else {
echo 'good';
}
 
if (ereg("[^a-zA-Z0-9_.-]", $userid)) {
echo 'bad';
} else {
echo 'good';
}

Hope this helps out someone else in the future.

An interesting article on the Net Neutrality debate. He gives a good overview of what’s going on with the whole thing. Give Me Bandwidth…

It’s probably the coolest thing I’ll see all day. Google Browser Sync will synchronize all your information – including bookmarks, history, persistent cookies, and saved passwords – accross all your computers that utilize the extension. SWEET!

I’m a grammar Nazi, so I think everyone should know the 10 flagrant grammar mistakes that make you look stupid..

This is a handle automation script for adding installation sources: Automate Insertion of YAST Installation Sources. I don’t know why this stuff isn’t in the default installation. C’est la vie.