What is the purpose of the function change_url_to_link in the PHP code provided?

The purpose of the function change_url_to_link in the PHP code provided is to convert any URLs within a given string into clickable hyperlinks. This function is useful for automatically detecting URLs within text content and making them clickable for users to easily navigate to the linked web pages.

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

// Example usage
$text = "Check out this website: https://www.example.com";
echo change_url_to_link($text);