Fix substr() for PHP 5.3 and revert previous commit