Re: Regex for Browser Versions
| From: | Monty | Date: | Thu, 05 Jun 2003 18:20:58 +0000 |
| Subject: | Re: Regex for Browser Versions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-150387@lists.php.net to get a copy of this message | ||
Maybe it might be easier to just use the get_browser() function:
http://www.php.net/manual/en/function.get-browser.php
Monty
> From: gsam@trini0.org (Gerard Samuel)
> Newsgroups: php.general
> Date: Thu, 05 Jun 2003 14:00:23 -0400
> To: php-general@lists.php.net
> Subject: Regex for Browser Versions
>
> Im trying to pull the Mozilla version and *possibly* the MSIE x.xx
> string out $_SERVER['HTTP_USER_AGENT']
> If I did this correctly, (MSIE\s\d\.\d{1,2})? should mean that if its
> there pull it out, else move on, since its not there.
> When viewing this script via a windows browser, it doesn't match the
> MSIE section. If I take out the trailing ?, it will match successfully.
> But when viewing it with a mozilla browser, the regex fails as there is
> not MSIE string in there.
> Any help with this would be appreciated.
> Thanks
>
> <?php
>
> var_dump($_SERVER['HTTP_USER_AGENT']);
> echo '<p>';
> preg_match('/^(Mozilla\/\d\.\d{1,2}|Opera\/\d\.\d{1,2})\s\(.*?(MSIE\s\d\.\d{1,
> 2})?.*?\)(\sOpera)?/',
> $_SERVER['HTTP_USER_AGENT'], $foo);
>
> var_dump($foo);
>
> ?>
>