NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Passing PHP Variables

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 06-18-2008, 10:38 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
freeflow's Avatar
Join Date: Dec 2006
Posts: 236
freeflow is on a distinguished road
 



Question Passing PHP Variables


Is there a way to solve the following problem?


PHP Script1:

$var1 = 'Free+Online+Games';

<a href="script2.php?q=<? echo "$var1";?>" <? echo "$var1";?></a>


PHP Script2:

$var1 = @$_GET['q'] ;

$var ="link.com/rss?p=var1$&amp;ei=UTF-8&amp;fl=0&amp;x=wrt";


The Problem:

By the time Free+Online+Games reach the link in script2 the +s are gone.
How can I pass the words without the +s being deleted?

Thanks.
freeflow is offline  
Old 06-18-2008, 10:42 AM   #2 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
urlencode it.
Daniel is offline  
Old 06-18-2008, 11:33 AM   #3 (permalink)
NamePros Member
 
edbrown's Avatar
Join Date: Dec 2006
Location: London
Posts: 101
edbrown is an unknown quantity at this point
 



Originally Posted by Daniel
urlencode it.
E.g.
????: NamePros.com http://www.namepros.com/programming/483205-passing-php-variables.html

Code:
$var1 = 'Free+Online+Games';  
<a href="script2.php?q=<? echo urlencode($var1);?>" <? echo "$var1";?></a>
__________________
ejbrown.net - XHTML/CSS/AJAX/PHP/mySQL development
edbrown is offline  
Old 06-18-2008, 12:16 PM   #4 (permalink)
NamePros Member
Join Date: Sep 2006
Posts: 99
Bruce_KD will become famous soon enoughBruce_KD will become famous soon enough
 



Everyone is missing the closing tag (">") on the original link after the ending quote. It is also a good practice to use full opening php tags, not shorthand. Most configurations support these shorthands, but there are still some that do not. You can also use <?php=

Code:
<?php
$var1 = 'Free+Online+Games';  
?>
<a href="script2.php?q=<?php=urlencode($var1)?>"> <?php=$var1?></a>
Also an efficiency tip, freeflow:
When echoing just a variable, don't put it inside of " "

Code:
echo $var;
is faster than
Code:
echo "$var";
It isn't by much, but if you're writing a large script, any piece of efficiency you can pick up is worth it. It is also a much better "Habit".
????: NamePros.com http://www.namepros.com/showthread.php?t=483205

I really enjoyed This Article that I found using StumbleUpon about php efficiency.


Bruce
Bruce_KD is offline  
Old 06-19-2008, 12:50 AM   #5 (permalink)
NamePros Member
Join Date: Apr 2008
Location: California
Posts: 104
pankirk is an unknown quantity at this point
 



Or you could try escaping the +'s. I'm not sure if it would work in this case? But just add a "\" in front of the +'s.
pankirk is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:27 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger