Category: php

  • Add a Rate Limit to Your Website

    Suppose you have a ressource on the web (for example an API) that either generates a lot of load, or that is prone to be abused by excessive use, you want to rate-limit it. That is, only a certain number of requests is allowed per time-period. A possible way to do this is to use…

  • preg_match, UTF-8 and whitespace

    Just a quick note, be careful when using the whitespace character \s in preg_match when operating with UTF-8 strings. Suppose you have a string containing a dagger symbol. When you try to strip all whitespace from the string like this, you will end up with an invalid UTF-8 character: $ php -r ‘echo preg_replace(“#\s#”, “”,…

  • Debugging PHP on Mac OS X

    [factolex] I have been using Mac OS X as my primary operating system for a few years now, and only today I have found a very neat way to debug PHP code, like it is common for application code (i.e. stepping through code for debugging purposes). The solution is a combination of Xdebug and MacGDBp.…

  • Eclipse Everywhere. Buah.

    It’s been a little quiet lately. This is because I am working on a cute little project that I will be able to present soon. More when the time is ready. There has been rumor lately that Zend (developer of PHP) will release a PHP Framework. This is nothing new, there has been a IDE…

  • Better code downloading with AJAX

    I’ve been playing with Code downloading (or Javascript on Demand) a little more. Michael Mahemoff pointed me at his great Ajaxpatterns in which he suggests a different solution: if (self.uploadMessages) { // Already exists return; } var head = document.getElementsByTagName(“head”)[0]; var script = document.createElement(‘script’); script.type = ‘text/javascript’; script.src = “upload.js”; head.appendChild(script); Via DOM manipulation a…

  • PHP and Multibyte

    ever messed around with umlauts or other non [a-z] letters? it’s quite horrible. for the german speaking region there are mainly two encoding types: iso8859-1 and utf-8. the former encodes each letter with one byte by extending old 7-bit ascii with 127 more letters, amongst others also umlauts. utf-8 includes up to 32,640 more letters…