xzazx Posted January 28, 2003 Share Posted January 28, 2003 Ok, I\'ve got a text in the DB, and in that text, is the text : http://www.xzazx.com Now, when I view it in the browser, it just displays this as an text, and I want it to be a link. How can i do this plz? here\'s what i mean : http://www.xzazx.com/forum/index.php?fid=1...c&id=19&start=0 thx! Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/ Share on other sites More sharing options...
effigy Posted January 28, 2003 Share Posted January 28, 2003 use a regular expression... create your own, or i think there are a few floating around on the forum here. Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/#findComment-286 Share on other sites More sharing options...
pallevillesen Posted January 28, 2003 Share Posted January 28, 2003 IF it is only urls in the text it is pretty easy to add some <a href=.... stuff... If the links are in a block of text like: For more information please go to [url]http://palle.ninja.dk[/url] For more information please go to http://palle.ninja.dk You probably need to do a really fancy regular expression to catch them all and make no mistakes OR do like this site and add some tags to the text (like the URL /URL tags used above). I have a quick cheat sheet for reg.expression on the folowing url http://www.daimi.au.dk/~biopv/public/reg.exp.php it\'s not only for php, so if you\'re stuck, look around... But my guess would be something like /.*(http://[^s].[^s]).*/ Matches http://anything.anything stop at spacecharacter.. But needs at least one dot in the webaddress... You then need to make the correct replace string, which is not so easy, look around - you\'re probably not the first facing this problem... P. P. Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/#findComment-292 Share on other sites More sharing options...
pallevillesen Posted January 28, 2003 Share Posted January 28, 2003 Try this function (not mine, just found it at http://www.bjclark.com/code/linkmail.phps ) function show_links($text) { $ret = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href="\\1://\\2\\3">\\1://\\2\\3</a>", $text); $ret = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href="mailto:\\1">\\1</a>", $ret); return($ret); } i.e. use echo show_links($text); P. Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/#findComment-294 Share on other sites More sharing options...
shivabharat Posted January 28, 2003 Share Posted January 28, 2003 A simple suggestion would be You know that which filed contails the link and when you retrieve the records (i.e the text) you can add the href tag before and after that. Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/#findComment-295 Share on other sites More sharing options...
aveach Posted January 28, 2003 Share Posted January 28, 2003 Here is how i display links returned from MYSQL database. if ($row[\"bar_website\"]) { echo \'<br><a href=http://\'. $row[\'bar_website\'] . \'>\' . $row[ \'bar_website\'] . \'</a>\';} $row[\'bar_website\'] returns \"www.whateveraddress.com\". Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/#findComment-297 Share on other sites More sharing options...
shivabharat Posted January 29, 2003 Share Posted January 29, 2003 That was indeed a Nice one! Simple and straight! Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/#findComment-298 Share on other sites More sharing options...
pallevillesen Posted January 29, 2003 Share Posted January 29, 2003 Hi Guys, I agree to Aveach\'s solution, but the problem is that if the text is stored like: $text = \"Welcome to our site, please visit http://www.biodyk.dk for information about our scubadiving or mail me palle@biodyk.nospam.dk\"; And you want to find adresses like the biodyk.dk address above, highlight and format it correctly... And it gets worse, what is people don\'t write the http:// or the mailto: ? You could be really evil, parse all places with www.word.* until a space and words with a @ in them - let php check if it exists and if it does insert the formatting. (I don\'t think you can get php to check if a mail address is valid though. P. Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/#findComment-305 Share on other sites More sharing options...
pallevillesen Posted January 29, 2003 Share Posted January 29, 2003 Ok, here\'s a function which returns all kinds of adresses: function showlinks($text){ // match any " word://word.word " $text = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href="\\1://\\2\\3">\\1://\\2\\3</a>", $text); // match any " word.word " no @ or //: allowed $text = eregi_replace( "[[:space:]]([^[:space:]|//:|@]*)(.[^[:space:]]*)([[:alnum:]#?/&=])[[:space:]]", " <a href="http://\\1\\2\\3">\\1\\2\\3</a>", $text); // match email adresses $text = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href="mailto:\\1">\\1</a>", $text); return $text; } $text = "Welcome to our site, please visit http://www.biodyk.dk for information about our scubadiving or mail me palle@biodyk.nospam.dk or try www.biodyk.dk <p>"; echo $text; echo showlinks($text); P. Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/#findComment-307 Share on other sites More sharing options...
jasmine25 Posted September 28, 2010 Share Posted September 28, 2010 wow...this is really a informative post ...thanks for sharing with us Quote Link to comment https://forums.phpfreaks.com/topic/101-link-from-mysql/#findComment-1116660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.