Jump to content

Archived

This topic is now archived and is closed to further replies.

xzazx

Link From MySQL

Recommended Posts

use a regular expression... create your own, or i think there are a few floating around on the forum here.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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\".

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.