M
M
Msim2015-07-16 21:27:11
PHP
Msim, 2015-07-16 21:27:11

How to parse json from a link?

$url = file_get_contents("

https://api.vk.com/method/wall.get?owner_id=-000000&domain='name'&v=5.34&count=100&filter='owner'&extended=1

 	");

I'm trying to get json and split it, if you follow the link, then everything turns out, but you can't help through file_get_contents in any way?
FIXED
$json = file_get_contents("http://api.vk.com/method/wall.get? ...  .json"); 
$safe_json = str_replace("\n", "\\n", $json);
$data = json_decode($json);

var_dump($data);
// var_dump($safe_json);

why safe_json was needed

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg Pavlov, 2015-07-16
@Msim

In general, it is better to use curl for requests.

$url = "https://api.vk.com/method/wall.get?owner_id=-000000&domain=%27name%27&v=5.34&count=100&filter=%27owner%27&extended=1";
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
curl_close($curl);
$content = json_decode($response,true);
print_r($content);

S
Sergey, 2015-07-16
@Pjeroo

php.net/manual/ru/filesystem.configuration.php#ini...

L
LittleFatNinja, 2015-07-16
@LittleFatNinja

json_decode()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question