Accessing the Zend_Application from a page
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
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 [...]
Online regex -> php tool
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. http://regex.larsolavtorvik.com/
Getting Ant to run on Windows 7 (64bit)
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
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 [...]
Regex – “The” searching
Say you have a list of movie titles, and you want to either sort them, or search through them, and some of them have “The ” at the start, for example: The Simpsons Simpson Street When doing a MySQL search: SELECT * FROM movies WHERE title LIKE “The Simp%”; Would only return the first row. [...]
Dependency Injections
Dependency Injections When creating PHP classes, particulary when utilising Unit tests, its a good idea to use dependancy injections. This enables us to use a robust reliable class which is not hard coded to rely (depend) on certain factors. If you were to use the Zend_Mail_Service in your class, it would work fine, but we [...]
« go back