Code Comments
Programming Forum and web based access to our favorite programming groups.I am trying to link the results from a query to a webpage. For exampe: Results Below: 5432 Brookwood Drive 704-434-7532 www.greatparks.com 3221 Farmfield Drive 704-656-0234 www.allyoucanbe.com 1212 Dalton Rd. 704-323-9999 www.beagoodscout.com I need a simple PHP script that will allow the user to click on the webpage link. I would appreciate anyone that can help me. Thanks. Rudy
Post Follow-up to this messageOn Tue, 16 Nov 2004 16:59:06 -0500, "Rudy" <bre@bellsouth.net> wrote: >I am trying to link the results from a query to a webpage. For exampe: > >Results Below: > >5432 Brookwood Drive 704-434-7532 www.greatparks.com >3221 Farmfield Drive 704-656-0234 www.allyoucanbe.com >1212 Dalton Rd. 704-323-9999 www.beagoodscout.com > >I need a simple PHP script that will allow the user to click on the webpage >link. I would appreciate anyone that can help me. Thanks. That's just a matter of putting an <a> tag around the address, surely? i.e. instead of print $row['url']; Then: sprintf("<a href='http://%s'>%s</a>", htmlspecialchars($row['url'])); htmlspecialchars($row['url'])); -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Post Follow-up to this message> sprintf("<a href='http://%s'>%s</a>",
> htmlspecialchars($row['url']));
> htmlspecialchars($row['url']));
Shouldn't it be:
sprintf("<a href='http://%s'>%s</a>",
urlencode($row['url']),
htmlspecialchars($row['url'])
);
Hilarion
Post Follow-up to this messageOn Wed, 17 Nov 2004 11:15:51 +0100, "Hilarion" <hilarion@SPAM.op.SMIECI.pl>
wrote:
>
>Shouldn't it be:
>
>sprintf("<a href='http://%s'>%s</a>",
> urlencode($row['url']),
> htmlspecialchars($row['url'])
> );
Actually that's what I typed first, then I had a think about it and went for
htmlspecialchars. Consider:
<?php
$row['url'] = 'localhost/test.php?blah=wurble+snurble';
printf("<a href='http://%s'>%s</a>",
urlencode($row['url']),
htmlspecialchars($row['url'])
);
?>
This doesn't do what's required; rather than outputting
<a href='http://localhost/test.php?blah=wurble+snurble'>
It outputs:
<a href='http://localhost%2Ftest.php%3Fblah%3Dwurble%2Bsnurble'>
Which isn't very useful. You don't want the / and ? encoded, you need them t
o
stay as literal characters because they're part of the URL.
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Post Follow-up to this messageThanks ...that helps!
Rudy
"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:ka6np0hk9054aai3ortngqn5d5ihj1j9o7@
4ax.com...
> On Wed, 17 Nov 2004 11:15:51 +0100, "Hilarion"
<hilarion@SPAM.op.SMIECI.pl>
> wrote:
>
>
> Actually that's what I typed first, then I had a think about it and went
for
> htmlspecialchars. Consider:
>
> <?php
> $row['url'] = 'localhost/test.php?blah=wurble+snurble';
>
> printf("<a href='http://%s'>%s</a>",
> urlencode($row['url']),
> htmlspecialchars($row['url'])
> );
> ?>
>
> This doesn't do what's required; rather than outputting
>
> <a href='http://localhost/test.php?blah=wurble+snurble'>
>
> It outputs:
>
> <a href='http://localhost%2Ftest.php%3Fblah%3Dwurble%2Bsnurble'>
>
> Which isn't very useful. You don't want the / and ? encoded, you need
them to
> stay as literal characters because they're part of the URL.
>
> --
> Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Post Follow-up to this messageYou are absolutely right about "urlencode" vs "htmlspecialchars". My mistake . Thanx for clarification. Of course data in DB should be allready properly urlencoded which means that not using any function in "href" value is an option too (but it's better to use "htmlspeci alchars" in case of typos and other mistakes). You made some typos in your code ( ");" instead of just "," in second line ) , but they are irrelevant. Hilarion
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.