0

Currently I have this url with paramanters. The $filter is in string format and rawurlencoded. Is it possible to use an array instead of string for the $filter? Like array('groups'=>array('11','22','33'))? Here's a sample code that is working.

$endpoint = 'https://api.com/queries';
$filter = "groups:['11', '22', '33']";
$url = $endpoint . '?filter=' . rawurlencode($filter);

It produces this url:

https://api.com/queries?filter=groups%3A%5B%2711%27%2C%20%2722%27%2C%20%2733%27%5D
0

1 Answer 1

0

Try to use urlencode() function just after to use json_encode() function like this :

$endpoint = 'https://api.com/queries';

$filterArray = array('groups' => array('11', '22', '33'));

$filter = urlencode(json_encode($filterArray));

$url = $endpoint . '?filter=' . $filter;

After this you can decode the URL-encoded JSON string and convert it back to an array like this :.

$filterString = $_GET['filter'];
$filterArray = json_decode(urldecode($filterString), true);
Sign up to request clarification or add additional context in comments.

1 Comment

Here's the created url https://api.com/queries?filter=%7B%22groups%22%3A%5B%2211%22%2C%2222%22%2C%2233%22%5D%7D but still not working. I've tried decoding it using burp suite and it has curly bracket on it. https://api.com/queries?filter={"groups":["11","22","33"]}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.