Page 1 of 1

preg match for Safari

Posted: Tue Aug 23, 2005 10:33 am
by mikebr
I am trying to get a preg_match for 'Safari', but the following doesn't seem to work, anyone see my mistake?

The input is 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412.6.2 (KHTML, like Gecko) Safari/412.2.2'

Code: Select all

if ( preg_match("/Safari ([0-9]\.[0-9]{0,2})/i", $this->get_user_agent(), $found) &&

				 strstr($this->get_user_agent(), "Mozilla") )

		{

		 	$this->browser = "Safari " . $found[1];

		}
Thanks in advance

Posted: Tue Aug 23, 2005 10:52 am
by nielsene

Code: Select all

preg_match("#Safari/([0-9]*)(\.[0-9]*){0,2}#i"....)
should be closer.

Posted: Tue Aug 23, 2005 11:31 am
by mikebr
Cheers, seems to work fine.

Posted: Tue Aug 23, 2005 3:00 pm
by feyd
FYI: get_browser()

if you can't use it, you can build your own using a combination of parse_ini_file() and some fun with regex..

Posted: Tue Aug 23, 2005 5:05 pm
by mikebr
The last example works fine but this does look interesting, thanks for the info.