0

Been at this for a while and cant figure it out so i thought id come to the ppl who know. my php / sql is so-so but.....this is what im trying to do / figure out..

i have a database setup to take in messages (of any sort) and works fine. The user enters data in a field, hits send, and the message gets logged.

But when a user puts in a link for example " http://www.google.com " its stored in the DB just fine but when its printed back onto the page, it comes back as plain text, what i want is that when the page throws back the message with the link in it, that the link is live and clickable.

Ive googled my a$# off but im guessing im searching for the wrong thing (or im missing something unbeknownst to me. )

Any tips/*direction* etc, ill gladly accept. also, I dont mind doing the work/research so if you have links only ill take those too.

Thanks in advanced.

somdow
  • 6,268
  • 10
  • 40
  • 58
  • Of course, you must construct an html link in order to have a clickable link...You need to recognize the link and surround it with the right html markup – Damien Pirsy Mar 05 '12 at 13:04

5 Answers5

1

you need regular expressions to detect links and convert them to <a href="$link">...</a> see the answer here:

PHP validation/regex for URL

Community
  • 1
  • 1
Not_a_Golfer
  • 47,012
  • 14
  • 126
  • 92
1

You need to parse messages plain text in order to find links. Then, change link texts by adding an anchor tag (<a>).

This link should help you.

Guillaume Poussel
  • 9,572
  • 2
  • 33
  • 42
  • thanks that got it working. On that link, the example kept throwing errors, turns out the problem was a quoting problem...double quotes within another set of double quotes. i just changed the inner pair to single and works 100%. thanks for the link. – somdow Mar 07 '12 at 03:58
0

You may want to check out http://www.php.net/manual/en/function.preg-replace.php for replacing regular expressions with something.

There you want to replace every website with a typical html link syntax like <a href="...">...</a>

Moritz
  • 266
  • 1
  • 8
0
<a href="<?php echo "your_field"; ?>"> <?php echo "your_field"; ?> </a>
Arif
  • 1,222
  • 6
  • 29
  • 60
  • The OP said *messages (of any sort)* so I guess there is not a field which contains only the link. Links are mixed up with plain text. – Guillaume Poussel Mar 05 '12 at 13:42
  • @S0pra in the above question, its stated that (when a user puts in a link for example " http://www.google.com " its stored in the DB just fine ) i m talking about that LINK_FIELD :-p – Arif Mar 05 '12 at 13:45
  • yeah thats what i mean S0pra. i have say a paragraph and in that paragraph of text, a link somewhere in there, i need a way to parse that on print into a clickable link. – somdow Mar 05 '12 at 13:57
0

Something like this should work (I took this from some code I wrote for a client):

$query = mysql_query("SELECT * FROM wcordersinfo WHERE dealer_id = '" . $dealer_id . "' && drawing_num = " . $_GET['reference_id'] . "");
    while ($orders = mysql_fetch_array($query)) {
        if ($orders['drawing_num'] != '') {
            $link_open = '<a href="http://www.example.com/dealers/order-details.php?reference_id=' . $orders['drawing_num'] . '">';
            $link_close = '</a>';
        } else {
            $link_open = $link_close = '';
        }

and then where you want to display the content:

<?php echo "<li>' . $link_start . $orders['carrier'] . $link_end . '</li>"; ?>
adamdehaven
  • 5,890
  • 10
  • 61
  • 84