?
Solved

php preg_match no ending delimiter

Posted on 2009-12-23
14
Medium Priority
?
789 Views
Last Modified: 2012-06-27
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
Comment
Question by:dschrishuhn
  • 6
  • 5
12 Comments
 

Author Comment

by:dschrishuhn
ID: 26116857

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
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1000 total points
ID: 26116956
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
 
LVL 11

Assisted Solution

by:asafadis
asafadis earned 1000 total points
ID: 26116965
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dschrishuhn
ID: 26116971
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26116976
There may be a simpler solution - can you tell us what the desired output is?  Thanks, ~Ray
0
 

Author Comment

by:dschrishuhn
ID: 26116984
Thanks - you guys are awesome!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26116986
@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
 

Author Comment

by:dschrishuhn
ID: 26117003
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26117016
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26118926
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
 

Author Closing Comment

by:dschrishuhn
ID: 31669677
Please don't yell :-P
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26119265
Merry Christmas to all... ~Ray
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question