Double byte and PHP (unicode problems)

November 2nd, 2006

A while back I ran into a problem with PHP, how can I read in files that have double byte (unicode) characters and display them in a form that any browser can read. Most programming languages don't handle these characters very well, and end up with non sense instead of passing through the correct text.

This function should be able to strip out any unicode characters from text and return them as html entities (something none of the core PHP functions are able to do).

PHP:
  1. function removeuni($content){
  2. preg_match_all("/[\x{90}-\x{3000}]/u", $content, $matches);
  3.  
  4. foreach($matches[0] as $match){
  5. $content = str_replace($match, mb_convert_encoding($match, "HTML-ENTITIES","UTF-8"), $content);
  6. }
  7.  
  8. return $content;
  9. }

Good code ruined?

August 16th, 2006

I happened across a really neat site the other day, called codegolf.com. Some of you might recall a similar scheme going on a while back called perl golf - well this is the same idea.

The deal is, there is a load of challenges set, and you have to write and submit the code to supply the required output of the challenge. However, there is one snag - you have to write it in as little code as possible. It has you really thinking laterally - outside of ways you might normally think of writing code, which I personally find fantastic (and depressing, realising how little shorthand I know!)

There is currently four languages you can submit in - PHP, Perl, Ruby and Python. Suggest that you hardcore execution-time monkies take a look at it and get scoring.

New Zealand Postcode Database

August 9th, 2006

Due to the lack of data from NZ Post, I've created this mysql database from the PDF on the NZ Post website.

All efforts have been made to ensure that there are no errors, but there are no guarantees, if you need 100% accurate data please buy NZ Post's PAF data.

Update: New Zealand Postcode Database version 2

Version 1:

nzpostcodes.sql.gz (467KB)
nzpostcodes.sql.bz2 (313KB)

Colorado Sheriffs To WarDrive For Safety

July 14th, 2006

The Sheriff's Department in Douglas County, Colorado says it's going to start warning computer users that their networks may be vulnerable to hackers. It plans on equipping its patrol cars with devices that detect unprotected computer networks, and distributing brochures to computer users in vulnerable areas, instructing them on how to password protect their networks.

More info here