Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
echo string with ampersand
Old 10-11-2008, 02:08 AM echo string with ampersand
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
I am having difficulty correctly printing a parameter that is coming from an internal link. The parameter looks like this http://www.example.com/link.php?nme=Happy & Fun&desc=Loads of fun for the kiddies.

I can parse nme and get "Happy" and parse desc and get "Loads of fun for the kiddies." but i can't get the "& Fun" part of the nme parameter.

Currently I am using this code to try and do it;

PHP Code:
htmlspecialchars_decode($_GET['nme'],ENT_QUOTES); 
but it doesn't seem to want to play the game.

I'm using PHP 5.2.6 which is hosted, if that's of any help.
scrobins is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-11-2008, 05:56 AM Re: echo string with ampersand
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
one reason why URIs should not have spaces in them

and query strings should NEVER EVER have a space in them.

http://uk.php.net/urlencode



( a space is a delimiter in HTTP so to all intents and purposes your URI ended after "Happy"
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-11-2008, 09:57 AM Re: echo string with ampersand
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
Cheers Chris but it doesn't have a problem with the desc parameter! I'm wondering whether the ampersand itself is halting the parameter as it thinks that another one is to be expected?

Any thoughts?
scrobins is offline
Reply With Quote
View Public Profile
 
Old 10-20-2008, 03:40 PM Re: echo string with ampersand
Super Talker

Posts: 116
Name: Paul
Location: South Africa
Trades: 0
I agree with Chrishirst, the spaces would be a problem, however I do see your point about the desc parameter working, I think that if you changed the code from &amp; to a normal "and" then things would work out, alternativly you could also look into escaping the chars that it is looking at as code or encoding your URI, it just seems like an awful amount of work, instead of just taking out the spaces, but not knowing the full extent of the project you are working on, only you can make that determination.
__________________
This was my latest holiday in
Please login or register to view this content. Registration is FREE
South Africa.
This was my favorite adventure holiday in
Please login or register to view this content. Registration is FREE
scorpioserve is offline
Reply With Quote
View Public Profile
 
Old 10-20-2008, 04:26 PM Re: echo string with ampersand
Extreme Talker

Posts: 160
Trades: 0
Because of the ampersand, the interpreter will see three 'get' pairs in your URL, here they are with their values :

nme : Happy
Fun :
desc : Loads of fun for the kiddies.

As has been stated, don't use raw spaces and ampersands in variable values being passed in URLs as they have special meaning. However, if you have to retain these characters encode them first, and decode after submission :

Code:
$nme_value  = base64_encode('Happy & Fun');
$desc_value = base64_encode('Loads of fun for the kiddies.');

echo <<<HTML
<a href="$_SERVER[PHP_SELF]?nme=$nme_value&amp;desc=$desc_value">click to test</a>
HTML;

echo '<hr />';
echo isset($_GET['nme']) ? base64_decode($_GET['nme']) : '';
echo '<br />';
echo isset($_GET['desc']) ? base64_decode($_GET['desc']) : '';
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to echo string with ampersand
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.14118 seconds with 12 queries