rkaartikeyan
rkaartikeyan

Reputation: 2007

Can I get return via URL

Can I get return via URL in php like below?

$var = http://www.example.com/give_data.php?id=4;

Upvotes: 0

Views: 1406

Answers (2)

Mick Hansen
Mick Hansen

Reputation: 2704

Your question is very confusing, but i think you want the contents of the file in your variable? For that you can use file_get_contents

$var = file_get_contents('http://php.net/manual/en/function.file-get-contents.php');

Upvotes: 3

Seldaek
Seldaek

Reputation: 42076

You can use file_get_contents() as such:

$var = file_get_contents('http://www.xyz.com/give_data.php?id=4');

But that will just return whatever the give_data.php script outputs as a string. If you need more advanced data-types, I would recommend using json_encode() in give_data.php and $var = json_decode($var); after getting the data to get back your original data. Note that this won't work for complex PHP objects. If you really really need, you can use serialize() and unserialize(), but it's not as standard and will work in PHP-only.

Upvotes: 2

Related Questions