indexing php error, undefined offset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mj777
    New Member
    • Sep 2021
    • 2

    #1

    indexing php error, undefined offset

    Errors:
    Notice: Undefined offset: 2 in short_codes_fun ctions.php on line 132
    Notice: Undefined offset: 3 in short_codes_fun ctions.php on line 132

    code line from 128 to 139

    if (!function_exis ts('adforest_ex tarct_link')) {

    function adforest_extarc t_link($string) {
    $arr = explode('|', $string);
    list($url, $title, $target, $rel) = $arr;
    $rel = urldecode(adfor est_themeGetExp lode($rel, ':', '1'));
    $url = urldecode(adfor est_themeGetExp lode($url, ':', '1'));
    $title = urldecode(adfor est_themeGetExp lode($title, ':', '1'));
    $target = urldecode(adfor est_themeGetExp lode($target, ':', '1'));
    return array("url" => $url, "title" => $title, "target" => $target, "rel" => $rel);
    }
    }

    please solve any one as soon as possible
    thank you
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Code:
    list($url, $title, $target, $rel) = $arr;
    list expects aleast 4 parameters.

    Code:
    $arr = explode('|', $string);
    Right side is returning an array of less than 4 values.

    Either ensure explode('|', $string) returns the minimum required number of values or pad the array to the required length using array_pad()

    Comment

    Working...