Page 1 of 1

Automatic Text to Links?

Posted: Tue Sep 10, 2002 8:32 pm
by qads
hi,
how can i turn all the urls/website addresses in $block_from_db into clickble links?

Code: Select all

<?php $block_from_db = "today www.site.com had blah blah with www.site-com.com";
print("$block_from_db");?>
like this forum turns any link into a clickble link, .e.g. http://www.somesite.com

i have no idea how to do it, i have searched quite alot of places but have't found anything for this.

please help

Posted: Tue Sep 10, 2002 8:51 pm
by dusty

Code: Select all

$block_from_db = preg_replace("/((http:\/\/)|(www\.))(&#1111;\S\.]+)\b/i", "&lt;a href="http://$3$4$5"&gt;$2$3$4$5&lt;/a&gt;", $block_from_db);

Posted: Tue Sep 10, 2002 8:51 pm
by hob_goblin

Code: Select all

$data = eregi_replace('(&#1111;&#1111;:space:]()&#1111;&#123;&#125;])(www.&#1111;-a-zA-Z0-9@:%_\+.~#?&//=]+)',
   '\\1<a href="http://\\2" target="_blank">\\2</a>', $data);

   $data = eregi_replace('(&#1111;&#1111;:space:]()&#1111;&#123;&#125;])(http://&#1111;-a-zA-Z0-9@:%_\+.~#?&//=]+)',
  '\\1<a href="\\2" target="_blank">\\2</a>', $data);
does the trick for me.

Posted: Tue Sep 10, 2002 10:38 pm
by phice
I get easily confuzed when I see the /^#$^3461/234!@%25 stuff. :oops:

Posted: Tue Sep 10, 2002 10:51 pm
by hob_goblin
it's just a list of characters that can be used in URL's

Posted: Wed Sep 11, 2002 1:03 am
by Takuma
Try looking http://www.phpbuilder.com/columns/dario19990616.php3 about Regular Expression. I think PREG does it faster than EREG.

Posted: Wed Sep 11, 2002 8:42 am
by qads
very nice :D , thanks alot!