Link to home
Start Free TrialLog in
Avatar of error77
error77

asked on

PHP to JSON how to

Hi all,

I was wondering how they do queries with parameters in the url with json/php

I'll explain what I mean...

Normally I know scripts that look like this:

http://mysite.com/myjson.json ... this will display the json data on the browser

now...

I seen some json url's that look like:

http://mysite.com/api/get_cars?year=2000

How is this done?

Thanks
Avatar of p_nuts
p_nuts
Flag of Netherlands image

Usually its a rewrite rule on the server forcing site.com/api to be handled by a PHP script.. In the PHP script you generate  a json encode in a variable and echo it.

Easy..
http://mysite.com/api/get_cars?year=2000
This may be a combination of a rewrite rule and a script that handles a GET-method request.  You might try adding var_dump($_GET) to see what is coming through in the request variables.
Avatar of error77
error77

ASKER

Is there anything on the net as an similar example that I can look at? Don't know what I should google for...
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is this question about a jQuery or AJAX activity?  If you can give us a link to a web site that illustrates the question we might be able to offer an explanation of the moving parts.