Dynadot โ€” .com Registration $8.99

Passing PHP Variables

Spaceship Spaceship
Watch

freeflow

Established Member
Impact
13
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$&ei=UTF-8&fl=0&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.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
urlencode it.
 
0
•••
Daniel said:
urlencode it.
E.g.

Code:
$var1 = 'Free+Online+Games';  
<a href="script2.php?q=<? echo urlencode($var1);?>" <? echo "$var1";?></a>
 
0
•••
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".

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


Bruce
 
0
•••
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.
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back