What is the best practice for making a list of URLs clickable in PHP without using a textarea?

When displaying a list of URLs in PHP, you can make them clickable by using the preg_replace function to find the URLs in the text and then replacing them with anchor tags. This way, users can easily click on the links to navigate to the specified URLs without the need for a textarea.

<?php
function makeUrlsClickable($text) {
    return preg_replace('/(http[s]?:\/\/[^\s]+)/', '<a href="$1" target="_blank">$1</a>', $text);
}

// Example usage
$urls = "Visit my website at http://www.example.com and check out my blog at http://blog.example.com";
echo makeUrlsClickable($urls);
?>