RobinTibbs Posted January 20, 2007 Share Posted January 20, 2007 ok heres the 411 ( or w/e these kids say nowadays ). in all their wisdom, Apple put the safari build numbers in the UserAgent string rather than the actual version numbers, but thankfully they have a table up on their developer site detailing which build numbers refer to which version numbers. to this extent i made this function:[code]function getSafariVersion($buildstring) { if($buildstring == "419.3") { return "2.0.4"; } elseif($buildstring == "417.9.3" | $buildstring == "417.9.2" | $buildstring == "417.8") { return "2.0.3"; } elseif($buildstring == "416.13" | $buildstring == "416.12") { return "2.0.2"; } elseif($buildstring == "412.5") { return "2.0.1"; } elseif($buildstring == "412.2.2" | $buildstring == "412.2" | $buildstring == "412") { return "2.0"; } elseif($buildstring == "312.6" | $buildstring == "312.5") { return "1.3.2"; } elseif($buildstring == "312.3.1" | $buildstring == "312.3") { return "1.3.1"; } elseif($buildstring == "312") { return "1.3"; } elseif($buildstring == "125.12" | $buildstring == "125.11") { return "1.2.4"; } elseif($buildstring == "125.9") { return "1.2.3"; } elseif($buildstring == "125.8" | $buildstring == "125.7") { return "1.2.2"; } elseif($buildstring == "100.1") { return "1.1.1"; } elseif($buildstring == "100") { return "1.1"; } elseif($buildstring == "85.8.1" | $buildstring == "85.8") { return "1.0.3"; } elseif($buildstring == "85.7") { return "1.0.2"; } elseif($buildstring == "85.5") { return "1.0"; }}[/code]was just wondering if there was a more efficient way of going about it? hmm. many thanks in advance Quote Link to comment Share on other sites More sharing options...
trochia Posted January 20, 2007 Share Posted January 20, 2007 I doub't it...as if Bill Gates or Steve Jobs ( and I notice this isn't " AppleSpeak"...lol ) did ...must be tweaked and bug free already? Sorry, I just had to toss that in...Jim Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 20, 2007 Share Posted January 20, 2007 Not really, I think using [b]if[/b]s or [b]elseif[/b]s are the fastest way to do this sort of thing.Using switch statements can be more compact but usually aren't any faster/more efficient. Quote Link to comment Share on other sites More sharing options...
Crimpage Posted January 20, 2007 Share Posted January 20, 2007 Can switch statements have multiple items per case, like in the IF statements aboveelseif($buildstring == "85.8.1" | $buildstring == "85.8") { return "1.0.3"; }Would you have to split that into 2 case's? That would make the switch very long... Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 21, 2007 Share Posted January 21, 2007 You would inline them like:[code]case "85.8.1":case "85.8":{ return "1.0.3";break }[/code] Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 21, 2007 Share Posted January 21, 2007 Personally, I find switch'es to be easier to read instead of a lot of elseif's. But, there's also another possibility which you might consider. Create an array of the values. Then you dont even need a function:[code]$SafariVersion['419.3'] = '2.0.4';$SafariVersion['417.9.3'] = '2.0.3';$SafariVersion['417.9.2'] = '2.0.3';$SafariVersion['417.8'] = '2.0.3';$SafariVersion['416.13'] = '2.0.2';$SafariVersion['416.12'] = '2.0.2';[/code]Then just get your version like this:[code]echo 'The safarri version is: ' . $SafariVersion[$buildstring];[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.