Forum Moderators: coopster

Message Too Old, No Replies

Changing hyperlinks automatically

         

Psycho Mantis

3:28 pm on Jan 9, 2005 (gmt 0)

10+ Year Member



Hi everybody.

I have a self-programmed PHP/MySQL-based calendar on my website. What I'd like to add is that when someone enters a hyperlink (via text box -> MySQL database) and doesn't use HTML-code (which is possible, but most people don't know HTML and don't look at the "how-to-post-links-tips" ;)), the link is automatically generated (clickable). Like it is on most of today's discussion forum softwares.

The problem is, that I don't know how to best call my problem and hence don't know how to search for it. If anyone of you have a solution or a tip where best to look at, I'd really appreciate!

Thanks! :)

mcibor

3:49 pm on Jan 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



search the text for [www....] or www. and change it to <a href="http://www...">http://www...</a>

search with eregi or strpos, then str_replace

Psycho Mantis

4:36 pm on Jan 9, 2005 (gmt 0)

10+ Year Member



Thanks for the reply.

This is what I so far got:


function hyperlink($text)
{
if (eregi("www.", $string)) {
    $sting = str_replace("<a href="http://www.");
}
}

However, in order to make this work, I'd need a way to add the end of the HTML hyperlink tag to the string. And I don't quite get how to do that. Aside from that, does eregi support OR in order to search for multiple alternatives?

Thanks!

Psycho Mantis

10:51 am on Jan 10, 2005 (gmt 0)

10+ Year Member



BUMP

Anyone?

Please! :-)

mcibor

9:45 pm on Jan 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Psychomantis! Welcome to webmasterworld!

This could be an answer:
$text = preg_replace('/(?<!=)(?<!])(http&#166;ftp)+(s)?:(\/\/)((\w&#166;\.)+)(\/)?(\S+)?/i','<a href="\0">\0</a>',$text );
$text = preg_replace('/\[url=(.*?)\](.*?)\[\/url\]/i','<a href="\\1">\\2</a>',$text);

And I recommend to you the discussion at
[webmasterworld.com...]
that's at forum about PHP topic Global variables

Best regards!
Michal Cibor