Replacement for PHP < 5 added, credits and thanks to Marco K. (Germany)