php - Creating a URL encoded string in smarty -


i trying create string of values taken variables in backend following structure:

before encoding:

transaction_id=0815/2009;transaction_cid=54ab;item_id=402163045080;item_va lue=25.20;item_quantity=1;  transaction_id=0815/2009;transaction_cid=54ab;item_id=402163045080;item_va lue=25.20;item_quantity=1; 

after encoding:

transaction_id%3d0815%2f2009%3btransaction_cid%3d54ab%3bitem_id%3d40216304 5080%3bitem_value%3d25.20%3bitem_quantity%3d1%3bitem_id%3d847163029054%3bi tem_value%3d16.81%3bitem_quantity%3d2 

i have managed create array necessary data in form:

'[{"transaction_id":"233684","transaction_cid":"d2871c13c507583048d8ecf4a16f94c0","i tem_id":"3524","item_value":"4915.13","item_quantity":"1"}]', 

but need these elements of array in url encoded string.

i out of ideas since try seems not work.

using json.stringify keeps ":" , """, using alert() or join keeps ":" , not performant.

example array:

arr : {key1: 'a', key2:'b', key3:'c'}

non encoded result:

str : 'key1=a;key2=b;key3=c'

desired result:

str : 'key1%3da%3bkey2%3db%3bkey3%3dc'

here code far:

[{foreach from=$orderarticles item="currorderarticle"}]         [{assign var="currbaseprice2" value=$currorderarticle->getbaseprice()}]      products_info.push(               {               transaction_id: '[{$order->oxorder__oxordernr->value}]',                transaction_cid: '[{$order->oxorder__oxuserid->value}]',                item_id: '[{$currorderarticle->oxorderarticles__oxartnum->value}]',               item_value: '[{$basket->getdiscountednettoprice()}]',               item_quantity: '[{$currorderarticle->oxorderarticles__oxamount->value}]'               });      [{/foreach}] 

any ideas on how can accomplished?

you can combine json_encode (or serialize if need use in php) , escape:

{$arr|json_encode|escape:'url'} 

also, if want make string shorter can use compression:

{$arr|json_encode|gzcompress|base64_encode|escape:'html'} 

though may bit overkill short arrays , you'll have base64_decode, gzuncompress , json_decode string when receive it.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -