1

I am stucked at one point in which I need to get JSON response if I pass .json behind the URL as below Example:

http://www.urlabc.com/home.json

The same way I need to get XML data like,

http://www.urlabc.com/home.xml

Please help me.

2 Answers 2

2

You can achieve it by using $_SERVER

 $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

This will return you actual path i.e http://www.urlabc.com/home.json

ANd by using pathinfo You get the extension of url as

echo $ext = pathinfo($actual_link, PATHINFO_EXTENSION);

if($ext=="json")
{
  // json code
}

if($ext=="xml")
{
  // xml code
}
Sign up to request clarification or add additional context in comments.

Comments

0
I think you should use pass "json" as query parameter
e.g.[http://www.example.com?type=json]

Also use Codeigniter Rest Server Click here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.