bammab
bammab

Reputation: 2563

why do i get Notice: Undefined offset: 65 and how to fix it

I keep getting this Notice: Undefined offset: 65 on line 31 which is this line if($k[$c]) $p = preg_replace('/\b'.base_convert($c, 10, $a).'\b/', $k[$c], $p);. How can I fix this?

//function to get source html
function get_data($url) {
    $curl_handle=curl_init();
    curl_setopt($curl_handle,CURLOPT_URL,$url);
    curl_setopt($curl_handle,CURLOPT_TIMEOUT,10);
    curl_setopt($curl_handle,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');
    curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,10);
    curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
    $html = curl_exec($curl_handle);
    curl_close($curl_handle);

    return $html;
}

//function to extract string beteen 2 delimeters
function extract_unit($string, $start, $end) {
    $pos = stripos($string, $start);
    $str = substr($string, $pos);
    $str_two = substr($str, strlen($start));
    $second_pos = stripos($str_two, $end);
    $str_three = substr($str_two, 0, $second_pos);
    $unit = trim($str_three);

    return $unit;
}

//function to decode packer endcoding
function js_unpack($p,$a,$c,$k) {
  while ($c--)
    if($k[$c]) $p = preg_replace('/\b'.base_convert($c, 10, $a).'\b/', $k[$c], $p);

  return $p;
}

//url source;
$adcrunch = get_data("http://adcrun.ch/BuVE");

//gather js_packer arguments
$arg_p = extract_unit($adcrunch, 'return p}(\'', ';\',');
$arg_a = extract_unit($adcrunch, '});\',', ',');
$arg_c = extract_unit($adcrunch, ',10,', ',\'|a0x1');
$arg_k = extract_unit($adcrunch, ',\'|', '\'.split');

$p = $arg_p;
$a = $arg_a;
$c = $arg_c;
$k = explode('|', $arg_k);

echo js_unpack($p, $a, $c, $k);

Upvotes: 0

Views: 1066

Answers (3)

Tobias Golbs
Tobias Golbs

Reputation: 4616

Or you use

if(array_key_exists($c,$k)) ...

Upvotes: 0

Shai Mishali
Shai Mishali

Reputation: 9382

Undefined offset means there is no index 65 in the array $k

You could "avoid" the warning by doing either:

if(isset($k[c]))

or

if(array_key_exists($c, $k))

Shai.

Upvotes: 1

genesis
genesis

Reputation: 50976

Try this one instead

if(isset($k[$c]) && $k[$c])

$c is probaly 65, and $k[65] does not exist

Upvotes: 0

Related Questions