Htmlspecialchars & links

I am using the code below to display a link to a form or not

if (isset($row[‘deliver_collect’])) {


if ($deliver_collect == ‘delivery’) {
$r_link =‘<a href=“?rec”>Recipient</a>’;
else if ($deliver_collect == ‘collection’) {

This works fine But when I echo $r_link

<?php echo htmlspecialchars($deliver_collect, ENT_QUOTES, ‘UTF-8’); ?> the link does not work, seems to be the htmlspecialchars.

If I just use <?php echo $r_link; ?> all works OK.

question since this is not a user input am I safe to just echo the $r_link

Thanks Kevin

The purpose of htmlspecialchars is to make sure none of the content is treated as HTML. If the content is supposed to contain HTML then you should not be using that function to convert the HTML to plain text.