daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jan 13th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $value = "en-us,en;q=0.7,ar-iq;q=0.3";
  4.  
  5. $accepted = array();
  6. if (preg_match_all("/\s*([^,;]+)(?:;\s*q=([\d.]+))?/", $value, $m, PREG_SET_ORDER)) {
  7.     foreach ($m as $lang) {
  8.         $accepted[] = array(
  9.             'lang' => $lang[1],
  10.             'q' => isset($lang[2]) ? (float)$lang[2] : 1
  11.         );
  12.     }
  13. }
  14.  
  15. usort($accepted, function($l1, $l2) {
  16.     return ceil((float)$l2['q'] - (float)$l1['q']);
  17. });
  18. var_dump($accepted);
RAW Paste Data
Top