[thelist] PHP encoding &s in a URL

Kelly Hallman khallman at wrack.org
Mon Sep 1 15:06:34 CDT 2003


On Mon, 1 Sep 2003, fstorr wrote:
> Okay, 2 replies saying encode, looks like I was nearly there.  This is 
> probably obvious, but why doesn't this code work?
> 
> <a href="encode.php?q=d&t">D&amp;T</a>
> <? $somevar = urlencode($_GET['q']);
> echo "somevar equals " .$somevar; ?>

<?php $q = "D&T"; ?>
<a href="encode.php?q=<?=urlencode($q)?>">D&amp;T</a>
<a href="encode.php?q=D%26T">D&amp;T</a>

# encode.php:
echo $_GET['q']; // php automatically urldecodes it...

-- 
Kelly Hallman
http://wrack.org/



More information about the thelist mailing list