Jump to content


Photo

Link From MySQL


  • Please log in to reply
9 replies to this topic

#1 xzazx

xzazx
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 January 2003 - 01:47 PM

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...c&id=19&start=0

thx!

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 28 January 2003 - 07:27 PM

use a regular expression... create your own, or i think there are a few floating around on the forum here.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 28 January 2003 - 10:58 PM

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....lic/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.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#4 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 28 January 2003 - 11:04 PM

Try this function (not mine, just found it at http://www.bjclark.c...e/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.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#5 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 28 January 2003 - 11:40 PM

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.
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#6 aveach

aveach
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 January 2003 - 11:54 PM

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

#7 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 29 January 2003 - 12:05 AM

That was indeed a Nice one! Simple and straight!
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#8 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 29 January 2003 - 12:29 PM

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.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#9 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 29 January 2003 - 12:59 PM

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.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#10 jasmine25

jasmine25
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 September 2010 - 07:11 AM

wow...this is really a informative post ...thanks for sharing with us




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users