1
<?php

$articleurl = 'http://m.tonton.com.my/webservices/article/get?uniqueid=6E619732-9501-4106-860C-  A20D0016E7F0&includeChildTypes=episode&parents=package_season%2Cpackage_content%2Cprogram&c hildren=1&sortBy=published_date&sortDirection=ASC&compact=0&cache=';
$articlecontent = file_get_contents($articleurl);
$articlejson = json_decode($articlecontent, true);
$arr = $articlejson["data"]["children"];
$max = max(array_keys($arr));
echo $max; //8 episode
for ($i=0; $i<=$max;++$i)
{
    $articleid[$i] = $articlejson['data']['children']['$i']['uniqueId'];
    $mediaid[$i] = $articlejson['data']['children']['$i']['version_viostream_id']['default'];
    $resources[$i] = 'http://m.tonton.com.my/webservices/media/getProgressiveResources?articleid='.$articleid[$i].'&mediaid='.$mediaid[$i].'&token=&cache=&manifestMode=progressive';
    print_r($resources[$i]);
}

I am trying to find all available array keys and insert the available variable into the link, but when I run the code, I get the error:

"Undefined index: $i in C:\xampp\htdocs\index.php on line 15 Notice: Undefined index: $i in C:\xampp\htdocs\index.php on line 16"

2
  • 3
    use [$i] instead of ['$i']. Commented Oct 22, 2013 at 11:15
  • also, always test if the data is an array; validate the data Commented Oct 22, 2013 at 11:36

1 Answer 1

1

You have a syntax error, not '$i', but $i:

$articleurl = 'http://m.tonton.com.my/webservices/article/get?uniqueid=6E619732-9501-4106-860C-  A20D0016E7F0&includeChildTypes=episode&parents=package_season%2Cpackage_content%2Cprogram&c hildren=1&sortBy=published_date&sortDirection=ASC&compact=0&cache=';
$articlecontent = file_get_contents($articleurl);
$articlejson = json_decode($articlecontent, true);
$arr = $articlejson["data"]["children"];
$max = max(array_keys($arr));
echo $max; //8 episode
for ($i=0; $i<=$max;++$i)
{
$articleid[$i] = $articlejson['data']['children'][$i]['uniqueId'];
$mediaid[$i] = $articlejson['data']['children'][$i]['version_viostream_id']['default'];
$resources[$i] = 'http://m.tonton.com.my/webservices/media/getProgressiveResources?articleid='.$articleid[$i].'&mediaid='.$mediaid[$i].'&token=&cache=&manifestMode=progressive';
print_r($resources[$i]);
}
Sign up to request clarification or add additional context in comments.

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.