How can one efficiently search and replace URLs in a text using PHP?
When searching and replacing URLs in a text using PHP, you can use the `preg_replace()` function along with a regular expression pattern to match the URLs. By using the appropriate regular expression pattern, you can efficiently search for URLs in the text and replace them with the desired URL or text.
$text = "Visit my website at https://www.example.com for more information.";
$pattern = '/(https?:\/\/[^\s]+)/';
$replacement = '<a href="$1">$1</a>';
$new_text = preg_replace($pattern, $replacement, $text);
echo $new_text;