function pllink($pid=0,$rnd=0){ $value = "<a href=player.php?pid=$pid&rnd=$rnd>$pid</a>"; echo $value; } PHP: pllink("Jack The Man",1); gives me: <a href=player.php?pid=Jack&rnd=1>Jack The Man</a> Why does it not show what's after the space?
need to quote the href part. function works fine. though you should url encode the spaces. function pllink($pid=0,$rnd=0){ $value = "<a href=\"player.php?pid=$pid&rnd=$rnd\">$pid</a>"; echo $value; }
Couple things I might consider: First, if you are using double quotes to enclose your variable then it is also acceptable to use single quotes on anything inside. For example, your URL would look like this: $value = "<a href='player.php?pid=$pid&rnd=$rnd' title='$pid'>$pid</a>"; It serves the same purpose and using the escape character, \, but is a bit easier to read. No matter which method you choose be aware that your PHP can be broken by passing a variable that contains a quote. If you are concerned about this then you might want to use str_replace() to escape any quotes. Second, shallowink brings up a good point about the spaces in your variable. When translated to a URL, spaces get rewritten as %20. It's not really a big deal but if you want a clean looking URL then you might want to consider replacing spaces with dashes.