You are here:  » Deprecated (ereg)


Deprecated (ereg)

Submitted by chrisst1 on Mon, 2013-05-13 09:29 in

Morning David

In tapestry.php am I safe to replace ereg with preg_match in the following two bits of code?

                case "regexp":
                  if (!ereg($voucher["match_value"],$product[$voucher["match_field"]]))
                  {
                    $isValid = FALSE;
                  }
                  break;
                case "notregexp":
                  if (ereg($voucher["match_value"],$product[$voucher["match_field"]]))
                  {
                    $isValid = FALSE;
                  }
                  break;

Thanks

Chris

Submitted by support on Mon, 2013-05-13 09:45

Hi Chris,

patterns in preg_match need to be delimited, e.g.

ereg("this",$text)

is equivalent to

preg_match("/this/",$test)

...so in your regexp voucher code mod, have a go with:

                case "regexp":
                  if (!preg_match("/".$voucher["match_value"]."/",$product[$voucher["match_field"]]))
                  {
                    $isValid = FALSE;
                  }
                  break;
                case "notregexp":
                  if (preg_match("/".$voucher["match_value"]."/",$product[$voucher["match_field"]]))
                  {
                    $isValid = FALSE;
                  }
                  break;

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Mon, 2013-05-13 13:00

Thank you David

Does the delimited also need to be applied to the filter in:

http://www.pricetapestry.com/node/740

    else
    {
      $filter_dropRecordFlag = !ereg($filter_data["text"],$text);
    }

If so is this correct

    else
    {
      $filter_dropRecordFlag = !preg_match("/".$filter_data["text"]."/",$text);
    }

Chris

Submitted by support on Mon, 2013-05-13 13:29

Hello Chris,

Ignore last, it's not actually required when the entire string is to be considered as the expression; which is correctly the case in the latest distribution.

If you're not sure about any deprecated changes required in 12/10B, if you look for the equivalent code in the latest distribution (13/03A) you'll be able to see the changes required, so in the above case, simply a direct swap of ereg for preg_match.

Cheers,
David.
--
PriceTapestry.com