Roaddoctor Posted March 8, 2015 Posted March 8, 2015 Error: Undefined offset: 1 in code function ehr_eval($matches) { $parts = explode('?',$matches[2],2); if (count($parts) == 0) { $p1 = $parts; $p2 = ''; } else { $p1 = $parts[0]; $p2 = $parts[1]; } $matches[2] = tep_href_link($p1,$p2); return $matches[2]; } // Look for %%+someurl%%- in the argument - replace it with // the output of tep_href_link(someurl) // function embedded_href_replace($string) { $output = stripslashes($string); $output = preg_replace_callback("/(%%\+)(.*)(%%-)/U", "ehr_eval", $output); return $output; } Would correct solution be ?? just looking for confirmation changing to: $p2 = isset($parts[1]) ? $parts[1] : null; function ehr_eval($matches) { $parts = explode('?',$matches[2],2); if (count($parts) == 0) { $p1 = $parts; $p2 = ''; } else { $p1 = $parts[0]; // $p2 = $parts[1]; $p2 = isset($parts[1]) ? $parts[1] : null; } $matches[2] = tep_href_link($p1,$p2); return $matches[2]; } // Look for %%+someurl%%- in the argument - replace it with // the output of tep_href_link(someurl) // function embedded_href_replace($string) { $output = stripslashes($string); $output = preg_replace_callback("/(%%\+)(.*)(%%-)/U", "ehr_eval", $output); return $output; } -Dave
♥kymation Posted March 8, 2015 Posted March 8, 2015 The proper test would be $p2 = ( array_key_exists ( '1', $parts ) ) ? $parts[1] : null; However, that's only covering up the error, not really fixing it. Whey is $parts[1] not being set? Is there some upstream error that is causing this? I would go looking for the real source of the problem, and then only add this code if the cause is something that is normal/expected. Regards Jim See my profile for a list of my addons and ways to get support.
Roaddoctor Posted March 8, 2015 Author Posted March 8, 2015 I was just quashing e-notices - the script works perfectly well with or without the change, so I don't know [ trust me I'm just winging it here:) ] if there is an upstream issue, but don't think so.. I just assumed php had evolved since the script was written (2003?) and a different syntax was now required to prevent the notice. learning as I go. Thx much for your reply! -Dave
MrPhil Posted March 8, 2015 Posted March 8, 2015 $parts is an array (product of explode()). You test if it has 0 elements (which I don't think it will, perhaps unless $matches was empty in the first place), but you don't handle the case of only one element (where only [0] exists). If it has two or more elements, [0] and [1] exist.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.