PHP Find replace URL in text to HTML Links

Hi Guys,

This is kinda straight forward thing to do using Regex magic so let go ahead and build our function which we will call plainUrlToLink()

Here is that snippet that you can just copy paste. Don’t forget to give this post a +1 if it helped you.

The Snippet

As you notice that I am not doing a case insensitive replacing that’s for a reason.

That’s that for our function but now lets check how to use it.



To use this function is simple. It will return a plain text content if

Above will print

Please note that this function is good for finding links in plain text only and will not work if you pass HTML to it.

Also if you want to include FTP URL detection then change you regex to this

I hope this helps. Every code has room for improvement, if you think this snippet can be improved please leave your feedback in comments, that will help other readers too.




  1. Thx, worked.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.