-2

How can i read this data i'm getting on my page via post? This are the variables as they appear on firebug under POST.

list[0].firstName   =test 1
list[0].name    =test
list[1].name    =test

I know that php replaces dots with underscores so i can access something like "address.box" by doing:

$_POST[address_box];

but i really can't figure out how to access all the above data. Seems like that php doesn't want to read whatever comes after the square brackets, overwriting all the fields with the same index (list[0].firstName seems to get overwritten by list[0].name .

Any solution?

EIDT: Here a var_dump of the data:

address.number  1
list[0].firstName   firstname0
list[0].name    name0
list[1].name    name1

array(2) { ["list"]=> array(2) { [0]=> string(10) "firstname0" [1]=> string(5) "name1" } ["address_number"]=> string(1) "1" }  
Machavity
  • 30,841
  • 27
  • 92
  • 100
nowhere
  • 1,558
  • 1
  • 12
  • 31
  • Was just about to ask the same question – FreshPro Nov 25 '13 at 11:38
  • Here http://stackoverflow.com/questions/68651/get-php-to-stop-replacing-characters-in-get-or-post-arrays . And also by testing it this is the way it works. – nowhere Nov 25 '13 at 11:38
  • 2
    seems for me like `$_POST['list'][0]['firstname']` – Royal Bg Nov 25 '13 at 11:42
  • we're getting close, but it gets only the first letter "t" when i try to echo it. – nowhere Nov 25 '13 at 11:48
  • 2
    `var_dump($_POST)` pls and show the output (edit the question) – Royal Bg Nov 25 '13 at 11:49
  • var_dump added in the question. – nowhere Nov 25 '13 at 11:53
  • You should remove the first 6 words from your question. – Alexander Nov 25 '13 at 11:56
  • `$_POST['list'][0]` contains `test 1` (firstName), and `$_POST['list'][1]` contains `test` (name). And `$_POST['address_number']` contains `1` (here the dot is transfered to underscore) – Royal Bg Nov 25 '13 at 11:57
  • i updated the example with better data. As you can see name0 is missing in the var_dump. – nowhere Nov 25 '13 at 12:00
  • Because it has the same key name. Either change `name` or `pacToAddList`. Or, I think, `pacToAddList.name[0]` would work, so `pacToAddList.name[1]` too. – Royal Bg Nov 25 '13 at 12:01
  • Yes, this is the problem. I'm getting data from another website which isn't using php but something else. I can't edit directly the stuff i'm getting from this site, so i wanted to know if there is any way in php to read this kind of notation. – nowhere Nov 25 '13 at 12:04
  • Is there any reason for that -1 so that i can make a better question?.. – nowhere Nov 25 '13 at 12:07
  • It seems for me pretty much like a js array, so can't you parse it via js and change the keys before posting to PHP – Royal Bg Nov 25 '13 at 12:08
  • Ok thanks, i hoped there could be a solution in php. If there isn't one i will ask the people working on the other site to fix it. – nowhere Nov 25 '13 at 12:11
  • 1
    If they don't hit into the $_POST array, I'm afraid if there's a better solution. Maybe you can check the RAW_POST_DATA. `var_dump($HTTP_RAW_POST_DATA)` – Royal Bg Nov 25 '13 at 12:13
  • Yes great idea! It doesn't work but i get all the info by doing file_get_contents('php://input'). I should be able to parse this. – nowhere Nov 25 '13 at 12:17

1 Answers1

-1

No. This is not possible within the PHP-language.

You must use either $object->field or $array['key'] notation.

Gustav
  • 2,902
  • 1
  • 25
  • 31