Plain text to link

Hello,
Is there a class out there for php that can take a block of text and extract the links in that text? I have found a few but it requires them to either have http or www in front of them. The text might look like:

Test text somesite.com
or
test text somesite.com?site=1&add=2

I have blocks of text stored locally that I want to extract all links into an array. But the text are from users so they put it in one way or another. I know UBB could be used but cant really use that right now. Any suggestions? I tried my own regex but just seems to not get all of them. Im looking to get links with our without http or www in front of it.

Until and unless you have fixed type of domains or links in the text, it is very difficult to write the code to extract the links from the text. You must be sure how the texts come in the source. Just for example: What if there is something like this?


This is mysite.it is another sentence here.

See here how to know if the mysite.it (I know this will not happen but maybe just because of typo) is not actually the link but if we write a common regular express to grab it the links having 2,3 characters’ top level domain names. So either we should have a list of possible top level domains or you should be sure for what particular top level domain can be in your source text. That’s why, http and/or www are commonly checked to find a link in a text. Hope to see some examples will be posted here for you from the regular express gurus here in SPF. I am not the one who writes regular expression myself rather I just always ask here in this forum :slight_smile: