Easy PHP question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert

    Easy PHP question

    Im trying to send a variable via GET to a php script like so:

    <a href="process.p hp?id=test & test">Link</a>

    Leaving spaces is no problem, but the & symbol (ampersand) cannot be
    displayed to the screen. I want it to show "test & test". Instead it
    displays just "test" without the rest following it.

    Can anyone tell me how to display the whole variable passed to
    process.php?

    TIA
    Rob
  • Andy Hassall

    #2
    Re: Easy PHP question

    On 12 Sep 2003 17:01:24 -0700, gojuka@si.rr.co m (Robert) wrote:
    [color=blue]
    >Im trying to send a variable via GET to a php script like so:
    >
    ><a href="process.p hp?id=test & test">Link</a>
    >
    >Leaving spaces is no problem, but the & symbol (ampersand) cannot be
    >displayed to the screen. I want it to show "test & test". Instead it
    >displays just "test" without the rest following it.[/color]

    In a URL, & is one of the separator characters (; being the other); so you
    have urlencode it for it to be part of a value within a URL.

    <a href="process.p hp?id=<?php echo urlencode('test & test')?>">Link</a>

    It'll come out as:

    <a href="process.p hp?id=test+%26+ test">Link</a>
    [color=blue]
    >Can anyone tell me how to display the whole variable passed to
    >process.php?[/color]

    And then & is special in HTML. You must encode it as &amp; in any output.

    echo htmlspecialchar s($_GET['id']);

    --
    Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
    Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

    Comment

    Working...