What are alternative approaches to converting links in HTML code using PHP functions to avoid the need for reversing the conversion process?

When converting links in HTML code using PHP functions, one common issue is the need to reverse the conversion process to retrieve the original links. An alternative approach to avoid this is to store the original links in a separate data structure, such as an associative array, and then use this data structure to retrieve the original links when needed.

<?php
// Original links array
$original_links = [
    'link1' => 'http://example.com/page1',
    'link2' => 'http://example.com/page2',
    'link3' => 'http://example.com/page3'
];

// Convert links in HTML code
$html_code = '<a href="{link1}">Link 1</a><a href="{link2}">Link 2</a><a href="{link3}">Link 3</a>';

foreach ($original_links as $key => $value) {
    $html_code = str_replace("{{$key}}", $value, $html_code);
}

echo $html_code;
?>