jQuery 1.x and 2.x detecting browser with PHP

jQuery 1.x and 2.x detecting browser with PHP

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">

  5. <?php

  6. // JQuery 1.x and 2.x URLs
  7. $jQuery1 = 'jquery-1.11.2.min.js';
  8. $jQuery2 = 'jquery-2.1.1.min.js';

  9. // Default
  10. $jQuery = $jQuery2;

  11. // User Agent
  12. $arr = explode(' ',mb_strtolower(str_replace(array('.','/'),' ',$_SERVER['HTTP_USER_AGENT']), 'UTF-8'));

  13. for($i=0; $i < count($arr); $i++){
  14. if($arr[$i] == "msie"){ // Internet Explorer ?
  15. if($arr[$i+1] <= 8){ // <= 8 version ?
  16. $jQuery = $jQuery1; // Jquery 1.x
  17. }
  18. }
  19. }

  20. // Print
  21. echo '<script src="'.$jQuery.'"><script>';
  22. ?>


  23. </head>

  24. <body>
  25. </body>
  26. </html>