<commit_before><?php

/**
* Parses a user agent string into its important parts
* 
* @author <NAME> <<EMAIL>>
* @link https://github.com/donatj/PhpUserAgent
* @param string $u_agent
* @return array an array with browser, version and platform keys
*/
function parse_user_agent( $u_agent = null ) { 
	if(is_null($u_agent)) $u_agent = $_SERVER['HTTP_USER_AGENT'];

	$data = array();

	if( preg_match('/\((.*?)\)/im', $u_agent, $regs) ) {

		# (?<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|Silk)(?: NT)?(?:[ /][0-9._]+)*(;|$)
		preg_match_all('%(?P<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|Silk)(?: NT)?(?:[ /][0-9._]+)*(;|$)%im', $regs[1], $result, PREG_PATTERN_ORDER);
		$result['platform'] = array_unique($result['platform']);
		if( count($result['platform']) > 1 ) {
			if( ($key = array_search( 'Android', $result['platform'] )) !== false ) {
				$data['platform']  = $result['platform'][$key];
			}
		}else{
			$data['platform'] = $result['platform'][0];
		}

	}

	# (?<browser>Camino|Kindle|Firefox|Safari|MSIE|AppleWebKit|Chrome|IEMobile|Opera|Silk|Lynx|Version)(?:[/ ])(?<version>[0-9.]+)
	preg_match_all('%(?P<browser>Camino|Kindle|Firefox|Safari|MSIE|AppleWebKit|Chrome|IEMobile|Opera|Silk|Lynx|Version)(?:[/ ])(?P<version>[0-9.]+)%im', $u_agent, $result, PREG_PATTERN_ORDER);

	//print_r( $result );

	if( ($key = array_search( 'Kindle', $result['browser'] )) !== false || ($key = array_search( 'Silk', $result['browser'] )) !== false ) {
		$data['browser']  = $result['browser'][$key];
		$data['platform'] = 'Kindle';
		$data['version']  = $result['version'][$key];
	}elseif( $result['browser'][0] == 'AppleWebKit' ) {
		if( ( $data['platform'] == 'Android' && !($key = 0) ) || $key = array_search( 'Chrome', $result['browser'] ) ) {
			$data['browser'] = 'Chrome';
			if( ($vkey = array_search( 'Version', $result['browser'] )) !== false ) { $key = $vkey; }
		}elseif( $key = array_search( 'Kindle', $result['browser'] ) ) {
			$data['browser'] = 'Kindle';
		}elseif( $key = array_search( 'Safari', $result['browser'] ) ) {
			$data['browser'] = 'Safari';<commit_msg>Added support for Wget (browser) and linux-gnu (OS). The UA sent is "Wget/1.12 (linux-gnu)"<commit_after><?php

/**
* Parses a user agent string into its important parts
* 
* @author <NAME> <<EMAIL>>
* @link https://github.com/donatj/PhpUserAgent
* @param string $u_agent
* @return array an array with browser, version and platform keys
*/
function parse_user_agent( $u_agent = null ) { 
	if(is_null($u_agent)) $u_agent = $_SERVER['HTTP_USER_AGENT'];

	$data = array();

	if( preg_match('/\((.*?)\)/im', $u_agent, $regs) ) {

		# (?<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|Silk|linux-gnu)(?: NT)?(?:[ /][0-9._]+)*(;|$)
		preg_match_all('%(?P<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|Silk|linux-gnu)(?: NT)?(?:[ /][0-9._]+)*(;|$)%im', $regs[1], $result, PREG_PATTERN_ORDER);
		$result['platform'] = array_unique($result['platform']);
		if( count($result['platform']) > 1 ) {
			if( ($key = array_search( 'Android', $result['platform'] )) !== false ) {
				$data['platform']  = $result['platform'][$key];
			}
		}else{
			$data['platform'] = $result['platform'][0];
		}

	}

	# (?<browser>Camino|Kindle|Firefox|Safari|MSIE|AppleWebKit|Chrome|IEMobile|Opera|Silk|Lynx|Version|Wget)(?:[/ ])(?<version>[0-9.]+)
	preg_match_all('%(?P<browser>Camino|Kindle|Firefox|Safari|MSIE|AppleWebKit|Chrome|IEMobile|Opera|Silk|Lynx|Version|Wget)(?:[/ ])(?P<version>[0-9.]+)%im', $u_agent, $result, PREG_PATTERN_ORDER);


	//print_r( $result );

	if( ($key = array_search( 'Kindle', $result['browser'] )) !== false || ($key = array_search( 'Silk', $result['browser'] )) !== false ) {
		$data['browser']  = $result['browser'][$key];
		$data['platform'] = 'Kindle';
		$data['version']  = $result['version'][$key];
	}elseif( $result['browser'][0] == 'AppleWebKit' ) {
		if( ( $data['platform'] == 'Android' && !($key = 0) ) || $key = array_search( 'Chrome', $result['browser'] ) ) {
			$data['browser'] = 'Chrome';
			if( ($vkey = array_search( 'Version', $result['browser'] )) !== false ) { $key = $vkey; }
		}elseif( $key = array_search( 'Kindle', $result['browser'] ) ) {
			$data['browser'] = 'Kindle';
		}elseif( $key = array_search( 'Safari', $result['browser'] ) ) {
			$data['browser'] = 'Safari';
{'fraction_non_alphanumeric': 0.2512, 'fraction_numerical': 0.006628571428571429, 'mean_word_length': 5.968152866242038, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2235466', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1657, 'n_words': 276}