Sorry, posted an incorrect question, will update soon.
I think you're looking for
I would set it to an intermediate variable, since you're using the
$_REQUEST array later instead of
$id = urlencode(htmlentities($_GET['id']));
and then later
<a href="https://test.com/page2.php?id=<?php print $id; ?>">Link</a>