Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameter passing

Status
Not open for further replies.

nesli

Programmer
Joined
Apr 3, 2001
Messages
2
Location
US

I need help in passing parameters with special chars

I have in script1.php
$x= 'A & B';

<a href=\&quot;script2.php?x=$x\&quot;>$x</a>

but when I echo $x in script2.php I get only A
the other part (& B) is lost. Why ? How to pass
the right way ?
 
To do this, you need some function to change characters like the ampersand (&) into their hex equivalents for the query string.

Something like this:
function intoHex($char) {
return '%'.bin2hex($char);
}

$myString = 'a & b';
print preg_replace(&quot;/([^\w\d])/e&quot;,&quot;intoHex('&quot;.&quot;\\1&quot;.&quot;')&quot;,$myString);

Note that that last preg was formatted for a pre 4.04 version of PHP...Newer versions may require a slight change.

hope this helps,

brendanc@icehouse.net
 
Yes, you can do it with regex, and in some specific cases you might need that, but PHP comes with a built-in function to handle escaping query strings, and it works fine for every situation I've needed. See
 
Oh yeah. :-)

Forever avoiding the obvious,
brendanc@icehouse.net
 

It helped
I went for the obvious and urlencode() and urldecode()
worked fine.
Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top