Let’s explain with a useful example. Let’s link the URLs written plainly in the entered text in HTML format. For this, you first need a pattern that will express a URL. I chose one of the ready-made samples on the internet. In expressions that match the preg_replace function, we can change the expressions we grouped in parentheses as we want.

<?php
// Pattern capturing URLs
$pattern = '(https?://(([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?.)+[a-zA-Z]{2,6}/?[^bs]+))';
 
$content = 'Baransel.dev //https://baransel.dev';
 
$replace = '<a href="$0">$1</a>';
 
echo preg_replace($pattern, $replace, $content); 

On the screen, the URL that we wrote in plain text becomes a link.