JSON php parsing trouble2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?Parsing values from a JSON file?How Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?Parse JSON in JavaScript?how can i check if RESTAPI is down using curl php

Nested Dynamic SOQL Query

How to read string as hex number in bash?

"Marked down as someone wanting to sell shares." What does that mean?

Why is participating in the European Parliamentary elections used as a threat?

Is there any common country to visit for uk and schengen visa?

Animating wave motion in water

Do I need to convey a moral for each of my blog post?

Does fire aspect on a sword, destroy mob drops?

What are the consequences of changing the number of hours in a day?

How to test the sharpness of a knife?

Knife as defense against stray dogs

Why is "la Gestapo" feminine?

How to understand 「僕は誰より彼女が好きなんだ。」

Fair way to split coins

Hot air balloons as primitive bombers

What kind of footwear is suitable for walking in micro gravity environment?

Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?

Homology of the fiber

Are hand made posters acceptable in Academia?

The English Debate

Unfrosted light bulb

When should a starting writer get his own webpage?

What is the tangent at a sharp point on a curve?

Turning a hard to access nut?



JSON php parsing trouble



2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?Parsing values from a JSON file?How Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?Parse JSON in JavaScript?how can i check if RESTAPI is down using curl php










0















I am trying to loop through a list of urls that have json to extract and store the data for later. Below is the code I am trying to run on a windows php machine, when I run it on a mac it works just fine but when ran on windows I get the below error



Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
Data received
PHP Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23



<?php

$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];

foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);

if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";


if($json->included)
foreach ($json->included as $id)
$newids[] = $id->id;



file_put_contents("ids.txt", implode(PHP_EOL,$newids));


?>









share|improve this question
























  • json_decode() is failing for some reason.

    – Barmar
    Mar 7 at 18:59






  • 1





    gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue

    – joy
    Mar 7 at 18:59






  • 1





    Try var_dump($response) to see what you're getting.

    – Barmar
    Mar 7 at 19:01






  • 1





    You should check $curl_errno before you try to use $response.

    – Barmar
    Mar 7 at 19:01











  • Here is a link to the actual file link

    – johncsmith427
    Mar 7 at 19:17















0















I am trying to loop through a list of urls that have json to extract and store the data for later. Below is the code I am trying to run on a windows php machine, when I run it on a mac it works just fine but when ran on windows I get the below error



Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
Data received
PHP Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23



<?php

$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];

foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);

if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";


if($json->included)
foreach ($json->included as $id)
$newids[] = $id->id;



file_put_contents("ids.txt", implode(PHP_EOL,$newids));


?>









share|improve this question
























  • json_decode() is failing for some reason.

    – Barmar
    Mar 7 at 18:59






  • 1





    gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue

    – joy
    Mar 7 at 18:59






  • 1





    Try var_dump($response) to see what you're getting.

    – Barmar
    Mar 7 at 19:01






  • 1





    You should check $curl_errno before you try to use $response.

    – Barmar
    Mar 7 at 19:01











  • Here is a link to the actual file link

    – johncsmith427
    Mar 7 at 19:17













0












0








0








I am trying to loop through a list of urls that have json to extract and store the data for later. Below is the code I am trying to run on a windows php machine, when I run it on a mac it works just fine but when ran on windows I get the below error



Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
Data received
PHP Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23



<?php

$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];

foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);

if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";


if($json->included)
foreach ($json->included as $id)
$newids[] = $id->id;



file_put_contents("ids.txt", implode(PHP_EOL,$newids));


?>









share|improve this question
















I am trying to loop through a list of urls that have json to extract and store the data for later. Below is the code I am trying to run on a windows php machine, when I run it on a mac it works just fine but when ran on windows I get the below error



Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23
Data received
PHP Notice: Trying to get property 'included' of non-object in D:sstkjson.php on line 23



<?php

$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];

foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);

if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";


if($json->included)
foreach ($json->included as $id)
$newids[] = $id->id;



file_put_contents("ids.txt", implode(PHP_EOL,$newids));


?>






php json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 19:00









Barmar

433k36256357




433k36256357










asked Mar 7 at 18:56









johncsmith427johncsmith427

185




185












  • json_decode() is failing for some reason.

    – Barmar
    Mar 7 at 18:59






  • 1





    gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue

    – joy
    Mar 7 at 18:59






  • 1





    Try var_dump($response) to see what you're getting.

    – Barmar
    Mar 7 at 19:01






  • 1





    You should check $curl_errno before you try to use $response.

    – Barmar
    Mar 7 at 19:01











  • Here is a link to the actual file link

    – johncsmith427
    Mar 7 at 19:17

















  • json_decode() is failing for some reason.

    – Barmar
    Mar 7 at 18:59






  • 1





    gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue

    – joy
    Mar 7 at 18:59






  • 1





    Try var_dump($response) to see what you're getting.

    – Barmar
    Mar 7 at 19:01






  • 1





    You should check $curl_errno before you try to use $response.

    – Barmar
    Mar 7 at 19:01











  • Here is a link to the actual file link

    – johncsmith427
    Mar 7 at 19:17
















json_decode() is failing for some reason.

– Barmar
Mar 7 at 18:59





json_decode() is failing for some reason.

– Barmar
Mar 7 at 18:59




1




1





gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue

– joy
Mar 7 at 18:59





gist.githubusercontent.com/blah/gistfile1.txt this url not found can you share url so i can debug issue

– joy
Mar 7 at 18:59




1




1





Try var_dump($response) to see what you're getting.

– Barmar
Mar 7 at 19:01





Try var_dump($response) to see what you're getting.

– Barmar
Mar 7 at 19:01




1




1





You should check $curl_errno before you try to use $response.

– Barmar
Mar 7 at 19:01





You should check $curl_errno before you try to use $response.

– Barmar
Mar 7 at 19:01













Here is a link to the actual file link

– johncsmith427
Mar 7 at 19:17





Here is a link to the actual file link

– johncsmith427
Mar 7 at 19:17












1 Answer
1






active

oldest

votes


















0














I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.



<?php

$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];

foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);

if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";

if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;



file_put_contents("ids.txt", implode(PHP_EOL,$newids));






?>






share|improve this answer























  • This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link

    – johncsmith427
    Mar 7 at 19:16












  • @johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data

    – joy
    Mar 7 at 19:38











  • @johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.

    – joy
    Mar 7 at 19:40










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050963%2fjson-php-parsing-trouble%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.



<?php

$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];

foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);

if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";

if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;



file_put_contents("ids.txt", implode(PHP_EOL,$newids));






?>






share|improve this answer























  • This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link

    – johncsmith427
    Mar 7 at 19:16












  • @johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data

    – joy
    Mar 7 at 19:38











  • @johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.

    – joy
    Mar 7 at 19:40















0














I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.



<?php

$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];

foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);

if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";

if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;



file_put_contents("ids.txt", implode(PHP_EOL,$newids));






?>






share|improve this answer























  • This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link

    – johncsmith427
    Mar 7 at 19:16












  • @johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data

    – joy
    Mar 7 at 19:38











  • @johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.

    – joy
    Mar 7 at 19:40













0












0








0







I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.



<?php

$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];

foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);

if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";

if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;



file_put_contents("ids.txt", implode(PHP_EOL,$newids));






?>






share|improve this answer













I think your request is not getting any response so the issue is coming, to prevent notice you can write code like below.



<?php

$urllist = file("https://gist.githubusercontent.com/blah/gistfile1.txt");
$newids = [];

foreach ($urllist as $url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
$json = json_decode($response);

if ($curl_errno > 0)
echo "cURL Error ($curl_errno): $curl_errorn";
else
echo "Data receivedn";

if(!empty($json) && !empty($json->included))
foreach ($json->included as $id)
$newids[] = $id->id;



file_put_contents("ids.txt", implode(PHP_EOL,$newids));






?>







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 19:11









joyjoy

796620




796620












  • This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link

    – johncsmith427
    Mar 7 at 19:16












  • @johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data

    – joy
    Mar 7 at 19:38











  • @johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.

    – joy
    Mar 7 at 19:40

















  • This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link

    – johncsmith427
    Mar 7 at 19:16












  • @johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data

    – joy
    Mar 7 at 19:38











  • @johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.

    – joy
    Mar 7 at 19:40
















This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link

– johncsmith427
Mar 7 at 19:16






This does not throw an error but doesnt return any data now though.. here is the link to the correct txt file link

– johncsmith427
Mar 7 at 19:16














@johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data

– joy
Mar 7 at 19:38





@johncsmith427 this example is working for me perfectly in my windows... I think Shutterstock blocked your ip so its not returning any data

– joy
Mar 7 at 19:38













@johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.

– joy
Mar 7 at 19:40





@johncsmith427 you can use proxy in windows to get data and also maintain some time from 2 request using sleep function.

– joy
Mar 7 at 19:40



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050963%2fjson-php-parsing-trouble%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived