• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

PHP Depraction function

We moved our shopping cart from one vendor to another.  The new vendor is using a newer version of php.  I was getting a Deprecated: Function ereg() is deprecated in C:\inetpub... on line...
for the first of these three lines

      ereg('\$Revisio' . 'n: ([^ ]+)', $this->revision, $rev);
            $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')');
      }

I changed the lines to the following:

      preg_match('/$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
            $this->setHeader('User-Agent', $this->title.'/'.$this->version.' (/'.$rev[#].'/)');
      }

I am now getting the following error:

Parse error: syntax error, unexpected '}', expecting ']' in C:\inetpub\... on line 2162

I tried changing the } to ] but then I just get a different error telling me that's not acceptable.  
0
PDIS
Asked:
PDIS
  • 2
1 Solution
 
käµfm³d 👽Commented:
Is $Reviso a variable in your code?
0
 
käµfm³d 👽Commented:
Also, why do you have a '}' at the end of that block of code? Where is the opening '{'?
0
 
Terry WoodsIT GuruCommented:
     ereg('\$Revisio' . 'n: ([^ ]+)', $this->revision, $rev);
            $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')');
      }

should be the same as:
      ereg('\$Revision: ([^ ]+)', $this->revision, $rev);
            $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')');
      }

which should be equivalent to:
      preg_match('/\$Revision: ([^ ]+)/', $this->revision, $rev);
            $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')');
      }

$rev[1] is simply the 1st array value of the $rev array, which remains the same for ereg and preg_match. $rev[0] is defined for preg_match, but not for ereg, but since we aren't using it here it doesn't matter. The $ in $Revision shouldn't need to be escaped with a backslash in this case, but it's clearer for anyone maintaining it if it is.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now