Do final link replacement with preg_replace_callback instead of str_replace on giant...