0

As you know PHP replaces dots and spaces from $_POST and $_GET keys with _.

Example:

<input name="foo bar" /> 

becomes $_POST['foo_bar'] after sent to server instead of $_POST['foo bar'].

Could you point me to a script that can handle this correctly even with arrays with depth (name="fo.o[bar][12][]")? Replacing . before sending the form with a character(s) is not an option since post is coming from an external non editable source.

Solution should handle raw post data.

2
  • 3
    why do you go through all the trouble? Commented Jul 12, 2013 at 9:44
  • Just don't use spaces and dots ... HTML can be manipulated even the source is external Commented Jul 12, 2013 at 9:48

1 Answer 1

1

This isn't an algorithmic solution to your problem, but it will solve your problem.

There are libraries out there designed to make processing request data more simple. One of them is the Request class from Symfony: http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Request.html

It wraps ParameterBag, so it is very easy to get data: http://api.symfony.com/2.3/Symfony/Component/HttpFoundation/ParameterBag.html

Basic usage is:

use Symfony\Component\HttpFoundation\Request;

$request = Request::createFromGlobals();
echo $request->get('parameter_name');

It handles multi-dimensional parameters as well.

You can read more about it at: http://symfony.com/doc/current/components/http_foundation/introduction.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.