Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
While typing 'codeproject.com' in a text editor of any website, how can you convert it into 'For those who code' as hyperlink and redirecting to codeproject.com through out the web.
Posted
Comments
LLLLGGGG 8-Sep-15 13:23pm    
Maybe like that: For those who code
LLLLGGGG 8-Sep-15 13:24pm    
I've written <a href="http://www.codeproject.com">For those who code</a>
waleed ahmed wadkar 14-Oct-15 10:35am    
Hey Mate ,

I just wanted to detect the string 'codeproject.com' type by any rookie user in any text form and automatically get convert it into hyperlink...any ideas ?

1 solution

Hi,

You may try to use regex in PHP (http://php.net/manual/en/function.preg-match.php[^]) in order to get that result. Follow this[^] tutorial.

What you have to do is simply detect the URL with this
#(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»""‘’]))#iS 

regex for instance. You can find other regexes here[^]. And then simply follow the point Finding and replacing strings explained on the aforementioned tutorial to convert the URL to an HTML expression.

Feel free to comment if you have other clues about it ;)

Hope this helps.

LG
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900