Re: question on parameter specification in href tag
| From: | Daniel Brown | Date: | Fri, 12 Dec 2008 19:41:41 +0000 |
| Subject: | Re: question on parameter specification in href tag | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-284562@lists.php.net to get a copy of this message | ||
On Thu, Dec 11, 2008 at 05:30, Xaver Thum <xaver.thum@t-online.de> wrote:
>
> But if I specify a hex color like #CC0000 instead of "red",
>
> <a
> href="http://www.anyurl.com?mypar=17&color=#CC0000">
> ...
>
> the color is ignored (probably because # starts a PHP comment).
> Is there any workaround for this problem ?
Hey, X;
Actually, it's skipped because it's seen as a page anchor. That's
a client-side only thing, and the browser would then be looking for:
<a name="CC0000" id="CC0000"></a>
Instead, skip the hashmark:
<a href="http://www.anyurl.com/?mypar=17&color=CC0000">
...
.... and have it parsed similarly to this:
<?php
if(strlen($_GET['color']) == 6 &&
preg_match('/[a-f0-9]{6}/i',trim($_GET['color']))) {
// Color is a legitimate HTML hexadecimal color
$_GET['color'] = strtoupper($_GET['color']); // Set upper-case
} else {
// Color is not legit, was not supplied, or this may be a lame
hack attempt
$_GET['color'] = 'CC0000'; // Force default color
}
$color = '#'.$_GET['color'];
?>
--
</Daniel P. Brown>
http://www.parasane.net/
daniel.brown@parasane.net || danbrown@php.net
50% Off Hosting! http://www.pilotpig.net/specials.php