Forum Moderators: coopster
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! :)
search with eregi or strpos, then str_replace
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!
This could be an answer:
$text = preg_replace('/(?<!=)(?<!])(http¦ftp)+(s)?:(\/\/)((\w¦\.)+)(\/)?(\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