浏览器版本匹配 - PHP 5.1.6中的正则表达式中断

I'm using a script to detect the browser and its version that is referenced multiple times on the get_browser page on php.net.

The file containing the script is saved as UTF-8 and actually it works fine´:

// relevant parts only where $ub stores the browser name like "Safari"
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
preg_match_all($pattern, $userAgent, $matches);

Now we're running a site on a server that uses PHP 5.1.6. Unfortunately it breaks the regex and displays this warning:

PHP Warning: preg_match_all() [function.preg-match-all]: Compilation failed: unrecognized character after (?< at offset 3 in /file.php on line 48

How must the pattern be updated to work properly with PHP 5.1.6?

查看全部
dqudtskm49788
dqudtskm49788
2013/02/14 14:28
  • regex
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复