-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

1
  • there is no much changes with urlencode of java and php, see the below answer, it may help Commented Aug 22, 2017 at 5:15

2 Answers 2

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']);

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

1 Comment

This is what i expected. Thank you Sathish Kumar D.
0

Try this

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

https://jsfiddle.net/eudgyj3u/

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.