Use preg_replace_callback instead of preg_replace