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

php preg_match no ending delimiter

Hi Everyone,

I'm getting:

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\XAMPP\xampp\htdocs\shop\includes\classes\language.php on line 87


Thanks for your help, I'm new to php.

-Omar
0
dschrishuhn
Asked:
dschrishuhn
  • 6
  • 5
2 Solutions
 
dschrishuhnAuthor Commented:

function get_browser_language() {
      $this->browser_languages = explode(',', getenv('HTTP_ACCEPT_LANGUAGE'));

      for ($i=0, $n=sizeof($this->browser_languages); $i<$n; $i++) {
        reset($this->languages);
        while (list($key, $value) = each($this->languages)) {
          if (preg_match('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $this->browser_languages[$i]) && isset($this->catalog_languages[$key])) {
            $this->language = $this->catalog_languages[$key];
            break 2;
          }
        }
      }
    }

Open in new window

0
 
Ray PaseurCommented:
It would help if you could tell us in plain language what you are trying to match!

See if this helps.  If not, please explain a little more about the objectives.
function get_browser_language() {
      $this->browser_languages = explode(',', getenv('HTTP_ACCEPT_LANGUAGE'));

      for ($i=0, $n=sizeof($this->browser_languages); $i<$n; $i++) {
        reset($this->languages);
        while (list($key, $value) = each($this->languages)) {
          if (preg_match('/^(' . $value . ')(;q=[0-9]\\.[0-9])?$/', $this->browser_languages[$i]) && isset($this->catalog_languages[$key])) {
            $this->language = $this->catalog_languages[$key];
            break 2;
          }
        }
      }
    }

Open in new window

0
 
asafadisCommented:
Try wrapping your pattern in slashes ('/').

function get_browser_language() {
      $this->browser_languages = explode(',', getenv('HTTP_ACCEPT_LANGUAGE'));

      for ($i=0, $n=sizeof($this->browser_languages); $i<$n; $i++) {
        reset($this->languages);
        while (list($key, $value) = each($this->languages)) {
          if (preg_match('/^(' . $value . ')(;q=[0-9]\\.[0-9])?$/', $this->browser_languages[$i]) && isset($this->catalog_languages[$key])) {
            $this->language = $this->catalog_languages[$key];
            break 2;
          }
        }
      }
    }

Open in new window

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dschrishuhnAuthor Commented:
Sorry for not being clear.  The /'s worked like a charm.

Thank you very much! I knew it had to be a simple syntax error.

-Omar
0
 
Ray PaseurCommented:
There may be a simpler solution - can you tell us what the desired output is?  Thanks, ~Ray
0
 
dschrishuhnAuthor Commented:
Thanks - you guys are awesome!
0
 
Ray PaseurCommented:
@dschrishuhn: You accepted the second solution - exactly the same code snippet as what I had posted earlier.  I will ask a moderator to reopen the question so you can award the points appropriately.  But if you would just take a moment to tell us what you want out of this code snippet maybe we can help you get a clearer and more dependable solution than REGEX.  Thanks, ~Ray
0
 
dschrishuhnAuthor Commented:
Sorry Ray, I agree.  I didn't realize I had refreshed the page.  And both comments were so close together that I accidentally accepted the second. I thought it was yours, hence the comment. (j/k, btw)

I upgraded apache servers and was converting the deprecated ereg() functions to preg_match.

0
 
Ray PaseurCommented:
Yeah, I have been replacing EREG with PREG, too.  A lot of it is just adding the delimiters, a little is adding the "i" where I used EREGI before.
0
 
Ray PaseurCommented:
Thanks for the points - I still think that a REGEX may not be the best design pattern here, but that is just a guess - not completely sure what your needed output would be, but if you want to describe it, there may be another way to skin this cat.

best regards, ~Ray
0
 
dschrishuhnAuthor Commented:
Please don't yell :-P
0
 
Ray PaseurCommented:
Merry Christmas to all... ~Ray
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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