PHP 5.5/5.2 compatible elimination of preg_replace /e modifier
Using private function and callback (avoids create_function, reputed to cause memory leaks)