PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
lmchaelichkatel
Forum Newbie
Posts: 8 Joined: Mon Nov 02, 2009 8:42 pm
Post
by lmchaelichkatel » Wed Nov 04, 2009 3:35 pm
Hi
I have an array which I send with
CURLOPT_POSTFIELDS option in
curl_setopt .
Code: Select all
$tab = array();
$tab['search'] = '';
$tab['filter_sectionid'] = '16';
$tab['catid'] = '0';
$tab['filter_authorid'] = '0';
$tab['filter_state'] = 'U';
$tab['toggle'] = '';
$tab['limit'] = '0';
$tab['limitstart'] = '0';
$tab['option'] = 'com_content';
$tab['task'] = 'remove';
$tab['boxchecked'] = '2';
$tab['redirect'] = '-1';
$tab['filter_order'] = 'section_name';
$tab['filter_order_Dir'] = '';
Well I need to add to this array $tab the values of cid[] but in php an array can countain only a unique key, so I can't do this :
Code: Select all
$tab = array();
$tab['search'] = '';
$tab['filter_sectionid'] = '16';
$tab['catid'] = '0';
$tab['filter_authorid'] = '0';
$tab['filter_state'] = 'U';
$tab['toggle'] = '';
$tab['limit'] = '0';
$tab['limitstart'] = '0';
$tab['option'] = 'com_content';
$tab['task'] = 'remove';
$tab['boxchecked'] = '2';
$tab['redirect'] = '-1';
$tab['filter_order'] = 'section_name';
$tab['filter_order_Dir'] = '';
// Add cid[] values
$tab['cid[]'] = '48';
$tab['cid[]'] = '47';
$tab['cid[]'] = '46';
$tab['cid[]'] = '42';
In this case I am blocked I don't know how to construct this array or send data using string instead of an array ?
Code: Select all
task=remove&boxchecked=2&redirect=-1filter_order=section_namefilter_order_Dir=&cid[]=48&cid[]=47&cid[]=46&cid[]=42
Think you
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Wed Nov 04, 2009 4:05 pm
For the CID use
Code: Select all
$tab["cid"] = array();
$tab["cid"][] = 48;
$tab["cid"][] = 47;
$tab["cid"][] = 46;
$tab["cid"][] = 42;
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Wed Nov 04, 2009 4:36 pm
Duplicate post:
108474
Code: Select all
$fields = array
( 'a' => '1'
, 'b' => array('1', '2', '3')
, 'c' => array
( 'ca' => '1'
, 'cb' => '2'
, 'cc' => '3'
)
);
print_r($fields);
$postfields = http_build_query($fields, '_', '&');
echo urldecode($postfields);
// a=1&b[0]=1&b[1]=2&b[2]=3&c[ca]=1&c[cb]=2&c[cc]=3
//curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
PHP Manual:
http_build_query()
Edit: This post was recovered from search engine cache.
Last edited by
McInfo on Thu Jun 17, 2010 1:40 pm, edited 1 time in total.
lmchaelichkatel
Forum Newbie
Posts: 8 Joined: Mon Nov 02, 2009 8:42 pm
Post
by lmchaelichkatel » Wed Nov 04, 2009 5:06 pm
Thinks for your replies. Is it mandatory to pass string by urlencode before send it to CURLOPT_POSTFIELDS ? because I don't use urlencode when I send array and I don't use it in CURLOPT_URL too, I send the url with & directly and it works.
Think you
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Wed Nov 04, 2009 6:42 pm
I used urlencode() to make the echoed string easier to read. The string stored in $postfields was not changed.
lmchaelichkatel wrote: Think
Thank
Edit: This post was recovered from search engine cache.