Jump to content

Extracting links etc from a string


envexlabs

Recommended Posts

Hey,

 

Lets use twitter for an example.

 

I have a string that says:

 

Hey everyone, check out my new portfolio site at mysweetsite.com

 

If the user was made to put a tag in from the the url, how would i extract the url from the string so i could format it properly?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/140107-extracting-links-etc-from-a-string/
Share on other sites

Hey,

 

I think i messed up on my explanation.

 

originally $string would = "Hey everyone, check out my new portfolio site at mysweetsite.com"

 

I would like to work some magic and have $string echo out:

 

Hey everyone, check out my new portfolio site at <a href="http://mysweetsite.com">mysweetsite.com</a>

 

So that it renders out a clickable link.

 

would preg_replace() still be the answer?

What if you have bad grammar and you did

 

"welcome to whatever.come to this page and lets see!!"

whatever.com would become a link and the e will be left out.. you need either www. or http:// to let the parser know its a link..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.