OK, I know how to do this but I’m interested in better/more elegant solutions (if any) for this problem.
Imagine I have the following string :
Mozilla/4.0 (compatible; MSIE 7.0;
Windows NT 5.1; Trident/4.0; GTB6.6;
Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; SV1) ; .NET CLR
1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
I’m interested to find the highest MSIE version in that string (in that case 7.0).
Currently I use explode and preg_match a couple of times in combination with str_replace then I loop between matches and then compare the version string. It works but it’s far from elegant. Any ideas on how to improve this?
Keep in mind that:
- The string can have any number of MSIE occurrences (or even none)
- MSIE is case insensitive
- MSIE is followed by a white space (space, tab…) then by the version. The version can contain number letters and dots. The version string is ended by either a white space, a ; or the end of the line.
Thanks!
Try: