0

I have received a string like this:

    id=123&nid=28&ntype=content&text=This%20is%20a%20note

I need to change this data to JSON. Is there any in-built function in PHP or some custom function?

1

2 Answers 2

3

Try like this...

$get_string = "id=123&nid=28&ntype=content&text=This%20is%20a%20note";
parse_str($get_string, $get_array);
echo json_encode($get_array);

You will get output like this...

{"id":"123","nid":"28","ntype":"content","text":"This is a note"}
Sign up to request clarification or add additional context in comments.

Comments

2
$tmp = parse_str($string);
echo json_encode($tmp);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.