Today I discovered that it is possible to “increment” alphabet characters in PHP.

$letter = "a";
$letter++;
echo($letter);

This will result in b. The same applies to capitals.
Note that character variables can be incremented but not decremented!

Now you wonder what happens if you reach the last letter in the alphabet:

$letter = "z";
$letter++;
echo($letter);

This will result in aa. The same applies to capitals.

Did you know this was possible with PHP?

 

A little while back I was trying to make a small IRC bot but I eventually lost my interest in it. While writing the bot I had to write a regex to match the raw IRC message pattern. A friend (thanks Jobe) on IRC came up with the following regex:

^(?:[:@]([^\\s]+) )?([^\\s]+)(?: ((?:[^:\\s][^\\s]* ?)*))?(?: ?:(.*))?$

It will match 4 groups (source, command, target and the parameters). A small example in JAVA:

Pattern pattern = Pattern.compile("^(?:[:@]([^\\s]+) )?([^\\s]+)(?: ((?:[^:\\s][^\\s]* ?)*))?(?: ?:(.*))?$");
Matcher matcher = pattern.matcher(line.subSequence(0, line.length()));
 
if (matcher.matches()) {
	//i.e irc.mibbit.net
	source = matcher.group(1);
	//i.e 433/NOTICE
	cmd = matcher.group(2);
	//i.e RoomBot/#mibbit
	target = matcher.group(3);
	//i.e I have 3093 clients and 1 servers
	param = matcher.group(4);
}

Would you have done differently?

© 2011 Joshua Lückers Suffusion theme by Sayontan Sinha