fix preg_replace call with /e flag, clean trailing spaces