What is OPML?
Regex for Browser Versions
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > PHP web-programming > Regex for Browser Versions 5 June 2003 22:17:45

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

Regex for Browser Versions

Gerard Samuel 5 June 2003 22:17:45
 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('/^(Mozi­lla\/\d\.\d{1,2}|Ope­ra\/\d\.\d{1,2})\s\(­.*?(MSIE\s\d\.\d{1,2­})?.*?\)(\sOpera)?/'­,
$_SERVER['HTTP_USER_AGENT'], $foo);

var_dump($foo);

?>


--
PHP General Mailing List (http://www.php.net­/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Monty 5 June 2003 21:20:58 permanent link ]
 Maybe it might be easier to just use the get_browser() function:

http://www.php.net/­manual/en/function.g­et-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.p­hp.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('/^(Mozi­lla\/\d\.\d{1,2}|Ope­ra\/\d\.\d{1,2})\s\(­.*?(MSIE\s\d\.\d{1,>­ 2})?.*?\)(\sOpera)?­/',> $_SERVER['HTTP_USER_AGENT'], $foo);>
var_dump($foo);>
?>>


--
PHP General Mailing List (http://www.php.net­/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Gerard Samuel 5 June 2003 22:17:45 permanent link ]
 True, but since the code is being run by 3rd parties, I don't have a
guarantee that
the browsecap.ini file is available on the server.

Monty wrote:
Maybe it might be easier to just use the get_browser() function:>
Monty>


--
PHP General Mailing List (http://www.php.net­/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > PHP web-programming > Regex for Browser Versions 5 June 2003 22:17:45

see also:
Problem with mail() function and exec
how to retrieve data from a web page
Re: how can i get rid of newlines…
пройди тесты:
see also:
JBOSS Error
Please somebody help

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .