What is the best practice for making a link clickable within a string in PHP?

To make a link clickable within a string in PHP, you can use the `preg_replace` function to search for URLs in the string and replace them with HTML anchor tags. This allows you to dynamically create clickable links within the text.

function makeClickableLinks($text) {
    $pattern = '/(http|https):\/\/[^\s]*/';
    $replacement = '<a href="$0" target="_blank">$0</a>';
    return preg_replace($pattern, $replacement, $text);
}

$string = "Check out this website: http://www.example.com";
echo makeClickableLinks($string);