PHP: Regular expression to make linkable url in string

Are you looking for a regular expression to make clickable url in the string? Yes!, you will get your solutions here:


echo preg_replace("/http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/", "$0", $string);

If you want to open url in new tab then :


echo preg_replace("/http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/", "$0", $string);


Comments

One response to “PHP: Regular expression to make linkable url in string”

Leave a Reply

Your email address will not be published. Required fields are marked *

*