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
dschrishuhnAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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
Ray PaseurCommented:
There may be a simpler solution - can you tell us what the desired output is?  Thanks, ~Ray
dschrishuhnAuthor Commented:
Thanks - you guys are awesome!
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
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.

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.
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
dschrishuhnAuthor Commented:
Please don't yell :-P
Ray PaseurCommented:
Merry Christmas to all... ~Ray
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.