Dealing with Errors in Custom Code

5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 5, 2016   (RSS)

By Perchpole - July 5, 2016

Hello, All -

I have a piece of code which I've just intergrated into a CMSB page. It's part of the PDT notification which allows me to show the variables from a PayPal transaction. Part of the code is shown below:

if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}

The code looks for variables which include the "=" symbol and breaks them into $key,$val pairs. Unfortunately, not every variable returned in the PDT notification includes the symbol. When run as a standalone script you don't notice there's a problem. However, because I'm running it through a CMSB page, it is logging an "undefined offset" error. It then keeps sending me emails to remind me!

Is there any way I can get CMSB to ignore the error or is there a better way for me to re-construct the line:

list($key,$val) = explode("=", $lines[$i]);

:0/

Perch

By Daryl - July 5, 2016

Hi Perch,

I wouldn't recommend ignoring the error. 

Instead, I'd check if "=" symbol exists first before exploding it.

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

By Perchpole - July 5, 2016

Hi, Daryl -

As I said in my original post, I know that "=" does not appear in every variable. I don't know how to run the check you mentioned. That's why I'm here for help!

:0)

Perch

By Perchpole - July 5, 2016

Perfect. It works!

Thanks for your help.

:0)

Perch