|
Filed Under (PHP Code Samples) by Anoop on May-26-2007
Code (php) <? function makeClickableLinks($text) { $text = html_entity_decode($text); $text = " ".$text; $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" target=_blank>\\1</a>', $text); $text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" target=_blank>\\1</a>', $text); $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target=_blank>\\2</a>', $text); $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1" target=_blank>\\1</a>', $text); return $text; } // Example Usage echo makeClickableLinks("This is a test clickable link: http://www.websewak.com You can also try using an email address like test@websewak.com"); ?>
Gera on August 27th, 2007 at 3:02 am #
Hello. I need some help regarding this topic (converting text to html, with links, using php). I have the following code that I have been working on. The problem is that this codes, inputs after every link in the text file, a // replace multiple spaces with single spaces // replace URLs with elements // start building output page .slug {font-size: 13pt; font-weight: bold} HEADER; // add page content // add page footer FOOTER; // display in browser // AND/OR // write output to a new .html file
Gera on August 27th, 2007 at 3:04 am #
Sorry It got cut up. I have the following code that I have been working on. The problem is that this codes, inputs after every link in the text file, the code adds a
Gera on August 27th, 2007 at 8:48 am #
Again, arrr!
brian on September 18th, 2007 at 2:16 am #
Thanks! this is exactly what I was looking for. There’s another one floating around that doesn’t work with simply “www.google.com”, it makes you type the http:// great job!
ZeroCool on February 17th, 2008 at 7:34 pm #
Thanks man, it work’s perfectly!
Yari on March 12th, 2008 at 3:40 am #
Thats a great script Anoop, i’ve modified it slightly to make sure it doesn’t convert EXISTING links, such as link. I’ve done this by adding a negate character class ([^]) before the main match: // http // https // www however, I couldn’t get this to work with converting emails… any ideas? Yari
Temistokles on June 11th, 2008 at 3:51 pm #
Yari: I think, this could work. $text = eregi_replace(’[^(href=|href=")](((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)’,
Chris on December 22nd, 2008 at 4:25 am #
Thanks!! Works fine. Post a comment
|
|