The homepage of Chris Tate-Davies
PHP
Accessing the Zend_Application from a page
Jul 27th
If, like me, you need to access some Zend_Application resources (such as multidb resources) – then you need a reference to the Zend_Application and the bootstrap. I use this:
if (null == $this->_application)
{
$this->_application = Zend_Controller_Front::getInstance()
->getParam('bootstrap');
}
Retrieve email using regex
Jun 23rd
ThisĀ horrendousĀ regular expression will parse a string and return a valid email address from it.
$email = "<'Freddy'> fred@live.com";
preg_match('/[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/', $email, $match);
echo $match[0];
This will return:
fred@live.com
Basically, if you pass an array as the third parameter of the preg_match method, it will be filled with the preg_match results, and the first item of the array will be the matching string. If you use capturing groups, these will also be filled. Read more about preg_match at the PHP site here.
I am told that this expression will match 99.9% of valid email addresses in the wild.
Online regex -> php tool
Jun 22nd
I’ve found an excellent online tool, where you can give it a regex, and it will spit out the PHP syntax for use with preg_replace, preg_match, etc.
I’m forever getting ‘Unknown modifier’ errors when trying to insert regex’s into my PHP code. This sorts it out for you.
Getting Ant to run on Windows 7 (64bit)
Apr 23rd
If like me, you use Ant to deploy builds, etc, and you have migrated to Windows 7 – you may well have troubles getting ant to run.
It all worked flawlessly under Ubuntu, but Windows is a different beast – here’s a step by step guide to getting it working.
Remove svn folders from Ubuntu
Apr 9th
When backing up a source code working copy, you don’t always want all the little .svn folders everywhere.
You can “export” the working copy, or if you forgot, you have remove them all.
Change the the folder containing the working copy (this is very important*)
cd /home/username/www/sitename/
And then remove them all, recursively with this command:
find -name "\.svn" -exec rm -rf {} \;
This will find all .svn files/folders in the current folder, and remove them and everything in them.
*if you do not ensure you are in the right folder, this command will remove all recursive folders, so if you are in the web root, it will remove all the svn information from all your sites… This is very important (that’s twice I’ve said that, so it must be)