I know there are at least 100 pages regarding this issue, and I did try a lot of them still with no luck.
It might be a very silly thing I might be missing some where but I'll grateful if someone can help me with it.
This is the php code:
<?php
$std_res = array();
$thumb_res = array();
$hashtag = $_GET['hashtag'];
if ($hashtag != "")
get_hashtag($hashtag);
function get_hashtag($hashtag){
$access_token = ACCESS_TOKEN;
$instagram = new Instagram(INSTA_CLIENT_ID, INSTA_CLIENT_SECRET, $access_token);
try {
$feed = $instagram->get('tags/'.$hashtag.'/media/recent');
}catch(InstagramApiError $e) {
die($e->getMessage());
}
$counter = 0;
//$std_res = array();
//$thumb_res = array();
foreach($feed->data as $item){
$std_res[$counter] = $item->images->standard_resolution->url;
$thumb_res[$counter] = $item->images->thumbnail->url;
$counter++;
}
print_r ($std_res);
//echo "<script> trial(); </script>";
}
?>
Then in javascript I trying access the content of $std_res
<script type="text/javascript">
//public function trial(){
var std_resol = <?php echo htmlspecialchars(json_encode($std_res), ENT_NOQUOTES); ?>;
//var std_resol = <?php echo json_encode($std_res ); ?>;
//var std_resol = <?php echo '["' . implode('", "', $std_res) . '"]' ?>;
for(var i=0;i<20;i++){
alert(std_resol[i]);
}
<!--
//var viewer = new PhotoViewer();
//viewer.add('images/1.jpg');
//viewer.add('images/2.jpg');
//viewer.add('images/3.jpg');
//-->
//}
</script>
I have tried lots of methods trying to access the array in javascript, it always throws a alert with undefined.
This is an example of the result in $std_res:
Array
(
[0] => https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/e15/11098632_1592161574372304_946830181_n.jpg
[1] => https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/e15/11137792_375372262654484_983054129_n.jpg
)
print_r ($std_res);?console.log(std_resol);to see how the data is being set?