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.

1
  • 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 Commented Mar 5, 2012 at 13:04

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Comments

0
<a href="<?php echo "your_field"; ?>"> <?php echo "your_field"; ?> </a>

3 Comments

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.
@S0pra in the above question, its stated that (when a user puts in a link for example " google.com " its stored in the DB just fine ) i m talking about that LINK_FIELD :-p
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.
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>"; ?>

Comments

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>

2 Comments

Note that "<a>" alone isn't valid, you need to indicate the href attribute too
yes I know that:D That was the short answer. I assumed he knows that :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.