How to convert string to json, with get all key's value in PHP

In this tutorial learn How to convert String to JSON, with get all key's value in php.

It will capture all URL string as an array to output.

You need JSON string as used json_encode to convert array to string.

<?php

parse_str("name=Nakiya&age=20&sex=Male&mobile=9998899999", $output);

echo json_encode($output,JSON_PRETTY_PRINT)."\n";
print_r($output); // if you need normal array.

?>
Above Example Output:

JSON format

   {
    "name": "Nakiya",
    "age": "20",
    "sex": "Male",
    "mobile": "9998899999"
   }
Array format

 Array
 (
    [name] => Nakiya
    [age] => 20
    [sex] => Male
    [mobile] => 9998899999
 )

No comments:

Post a Comment