Easy PHP question

This is a discussion on Easy PHP question within the PHP Language forums, part of the PHP Programming Forums category; Im trying to send a variable via GET to a php script like so: <a href="process.php?...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-13-2003
Robert
 
Posts: n/a
Default Easy PHP question

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

<a href="process.php?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
Reply With Quote
  #2 (permalink)  
Old 09-13-2003
Andy Hassall
 
Posts: n/a
Default Re: Easy PHP question

On 12 Sep 2003 17:01:24 -0700, gojuka@si.rr.com (Robert) wrote:

>Im trying to send a variable via GET to a php script like so:
>
><a href="process.php?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.


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.php?id=<?php echo urlencode('test & test')?>">Link</a>

It'll come out as:

<a href="process.php?id=test+%26+test">Link</a>

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


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

echo htmlspecialchars($_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)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0