Sanju Menon
Sanju Menon

Reputation: 685

Querystring url encode

i am getting a querystring parameter like companyname=Larson&tubro. Its a single string. But my script is just breaking it after '&'. What is the solution to take this as a single string in PHP. I tried like the below:

 <A onclick="window.open('comparitive_files/price_add.php?supplier_name= + urlencode({$supplier_name})&amp;tender_id={$tender_id}','mywindow','width=1200,height=800,scrollbars=yes,resizable=yes')" 
  href="#">

Upvotes: 0

Views: 140

Answers (4)

Mattigins
Mattigins

Reputation: 1016

You are trying to use php functions outside of php. Try something like this.

echo '<A onclick="window.open(\'comparitive_files/price_add.php?supplier_name='.urlencode($supplier_name).'&tender_id='.$tender_id.',\'mywindow\',\'width=1200,height=800,scrollbars=yes,resizable=yes\')" href="#">';

Upvotes: 2

Ninju
Ninju

Reputation: 2530

Use urlencode for encoding

 urlencode($companyname);

and urldecode for decoding

 urldecode($companyname)

Upvotes: 0

chandresh_cool
chandresh_cool

Reputation: 11830

You can try urlencode

 urlencode($var);

Upvotes: 1

Ivar
Ivar

Reputation: 6818

& is used to seperate variables in a querystring. Instead use &amp;.

To prevent any other illegal characters from getting in your querystring, use urlencode()

Upvotes: -1

Related Questions