Escaping dollar signs in PHP regular expressions
I had some problems matching dollar signs in PHP regexp’s:
$str = 'Bacon $ham eggs and $spam';
preg_match_all("|\$|", $str, $matches);
print_r($matches);
Gives
Array
(
[0] => Array
(
[0] =>
)
)
It does work when double escaping the $
preg_match_all("|\\$|", $str, $matches);
Gives
Array
(
[0] => Array
(
[0] => $
[1] => $
)
)
This problem occurs because PHP substitutes $variables in strings enclosed in “double quotes”. So, actually the problem can very easily be solved by just replacing double with single quotes:
preg_match_all('|\$\' $str, $matches);
Objective best practices for WordPress plugin development
Objective best practices for WordPress plugin development
Must-read thread for any WP plugin coders. I’ve written two suggestions, about using a template mechanism and about using classes and proper PHP5 OO-code.
iReader plugin mimics Safari’s ‘Reader’ option almost to perfection

Thanks to a Superuser question i asked a few weeks ago i discovered the wonderful iReader plugin for Google Chrome. It mimics Safari 5.0′s new Reader functionality almost to perfection (hopefully Apple won’t be pointing their copyright lawyers to this blogpost right now). The ‘Reader’ option in Safari gives you an uncluttered view of an article on a website without ads and nice fonts, a bit like Readability or Instapaper but with multi-page support.
It doesn’t quite render multi-page articles perfectly, such as the infamous Wired article on the death of the web. But Safari’s Reader doesn’t render that correctly too.
There’a also a beta version available for Firefox.
jQuery mobile
New version of jQuery targeted for mobile touch devices. Release date is somewhere end of this year.
Javascript and sorting
Sorting in Javascript using the Array.sort() function doesn’t work how i thought it did:
var foo = [3, 4, 5, 2, 1];
foo.sort(function(a,b) {
return a < b;
});
console.log(foo);
In Firefox this gives the result you expect ([1,2,3,4,5]), but in Chrome and Safari, it doesn't (and in IE too probably). When re-reading the spec at Mozilla's dev site i discovered why:
If compareFunction(a, b) is less than 0, sort a to a lower index than b. (…) If compareFunction(a, b) is greater than 0, sort b to a lower index than a.
So, the return value should not be true or false but -1 or 1. The example above should be written as:
foo.sort(function(a,b) {
return a - b;
});
» An overview of all articles can be found in the archive.

