Skip to main content

Replace URLs in text with HTML links



Here is a design though: For example is I put a link such as







http://example.com







in textarea . How do I get PHP to detect it’s a http:// link and then print it as







print "<a href='htttp://example.com'>http://example.com</a>";







I remember doing something like this before however, it was not fool proof it kept breaking for complex links.





Another good idea would be if you have a link such as







http://example.com/test.php?val1=bla&val2blablabla%20bla%20bla.bl







fix it so it does







print "<a href='http://example.com/test.php?val1=bla&val2=bla%20bla%20bla.bla'>";

print "http://example.com/test.php";

print "</a>";







This one is just an after thought.. stackoverflow could also probably use this as well :D





Any Ideas



Source: Tips4all

Comments

  1. You can also parse the comment text looking for valid urls with preg_match and an adequate regular expression.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?