PHP5 class for bit.ly API
Having chosen to convert a bunch of long URLs using bit.ly, I slightly modified and packaged in a simple PHP5 class the code written by David Walsh. The following is an example of usage of this class: $mbit = new BitlyWalsh($login, $apiKey); echo $mbit->getShort($yourLongUrl); // echo $mbit->getLong($bitlyShortUrl); You can download here this basic class.
Google Spelling
I’ve written a short PHP script that outputs what I call “the Google spelling” :) a 26 words list of the most frequent words/phrases taken from Google Suggest. You can also pass the language to it, so the today’s (2010-06-07) English list is amazon bank of america craigslist dictionary ebay facebook gmail hotmail imdb jet [...]
Geocoding behind a proxy
The official PHP/MySQL Google Maps Geocoding example uses simplexml_load_file that doesn’t handle a proxy so if your script is behind a proxy, you can’t use it. The problem can be overcome by using stream_context_create and file_get_contents as described in the following snippet: $request_url = $base_url . "&q=" . urlencode($address); $params = array ( ‘http’ => [...]
I feel like a scuba debugger
I’ve just spent the last two days trying to smash a treacherous bug in a bunch of quite old PHP scripts: each file was very “simple”… no classes or functions, just a black forest of nested if/else statements with a few redirects here and there. It was so messy that I was forced to diff [...]
Filter chains using reflection
A very common problem is submitting each object of an array to a set of tests: if a given object fails a given test, the system marks the object as “failed” without running the remaining tests. The classical solution is writing a class for the test, with a method for each test and another method [...]
General belief about memory_get_usage
I’ve discussed with a friend the effect on memory of assigning strings by reference (or by value) within PHP5. There is a false belief about it: I’ve just written a short script that, using memory_get_peak_usage and memory_get_usage, reports the memory used by emalloc in the following case $a = fit_the_string(); $b = fit_the_string(); $c = [...]
DokuWiki passes E_STRICT test, others don’t
Having read that The Zend Framework codebase must be E_STRICT compliant. on the latest version of a XAMPP server I’ve tested with E_STRICT the three LA(M)P programs that I mostly use: DokuWiki (2007-06-26b), Joomla! (1.5 RC3) and WordPress (2.3.1). Of course DokuWiki is the simplest of them but I was surprised to discover that it [...]
An accessible email cloaking technique
I suppose that you do not write your email on webpages but if you have to deal with people that do want to, you have to find some trick to protect them. I’ve found a good list of techniques to achieve this task but when you can’t use anything like CSS, images or JavaScript it’s [...]
mkdir, what else? :)
Reading the referers of this website, I found that someone reached it querying a search engine for PHP script to create folder recursively You can use this one-liner: mkdir(‘/the/new/folder/tree/that/you/want’, 0755, true);
