-2

How to pass jsondata in URL in php, I searched and tried using http_build_query() it is passing like this

    http://abcd/xyz?id=12&name=mansfh

but I want URL to be like this

    http://abcd/xyz?jsondata={"id":"12","name":"mansfh"} 

Please, someone, help me

Sujal Patel
  • 2,444
  • 1
  • 19
  • 38
Mahantesh
  • 347
  • 5
  • 20

2 Answers2

1

Try with url encode, it works worth

<?php
$json_str = "{'id':'12','name':'mansfh'}";
$url_json = urlencode($json_str);
$url = "http://abcd/xyz?jsondata={$url_json}";

//to get the JSON again in http://abcd/xyz page

$json_str = urldecode($_GET['jsondata']);

?>
Sathish Kumar D
  • 274
  • 6
  • 20
0

Try this

<a href= 'http://abcd/xyz?jsondata={"id":"12","name":"mansfh"}' target="_blanck">a</a>

https://jsfiddle.net/eudgyj3u/