Whats the best way?
| From: | Gerard Samuel | Date: | Sat, 18 May 2002 16:38:37 +0000 |
| Subject: | Whats the best way? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-98267@lists.php.net to get a copy of this message | ||
Well this is the first time actually creating a regex.
It works, but was wondering if the regex was created properly.
HTTP_ACCEPT_LANGUAGE is 'en-us, en;q=0.75, nl;q=0.50, fr;q=0.25'
/* Explode the browser report to get each language */
$foo = split(',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
/* Perform a regex to get the first 2 letters for each language reported */
foreach ($foo as $bar) {
$string = preg_replace("/([a-z]{2})|(-[a-z]{2})|(;q=[0-9]\.[0-9]{2})/i", "$1", trim($bar));
$array[] = $string;
}
Thanks