public static function uncomment_rfc822($string)
	{
		$string = (string) $string;
		$position = 0;
		$length = strlen($string);
		$depth = 0;

		$output = '';

		while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
		{
			$output .= substr($string, $position, $pos - $position);
			$position = $pos + 1;
			if ($string[$pos - 1] !== '\\')
			{
				$depth++;
				while ($depth && $position < $length)
				{
					$position += strcspn($string, '()', $position);
					if ($string[$position - 1] === '\\')
					{
						$position++;
						continue;
					}
					elseif (isset($string[$position]))
					{
						switch ($string[$position])
						{
							case '(':
								$depth++;
								break;

							case ')':
								$depth--;
								break;
						}
						$position++;
					}
					else
					{
						break;
					}
				}
			}
			else
			{
				$output .= '(';
			}
		}
		$output .= substr($string, $position);

		return $output;
	}
public static function uncomment_rfc822($string)
	{
		$string = (string) $string;
		$position = 0;
		$length = strlen($string);
		$depth = 0;

		$output = '';

		while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
		{
			$output .= substr($string, $position, $pos - $position);
			$position = $pos + 1;
			if ($string[$pos - 1] !== '\\')
			{
				$depth++;
				while ($depth && $position < $length)
				{
					$position += strcspn($string, '()', $position);
					if ($string[$position - 1] === '\\')
					{
						$position++;
						continue;
					}
					elseif (isset($string[$position]))
					{
						switch ($string[$position])
						{
							case '(':
								$depth++;
								break;

							case ')':
								$depth--;
								break;
						}
						$position++;
					}
					else
					{
						break;
					}
				}
			}
			else
			{
				$output .= '(';
			}
		}
		$output .= substr($string, $position);

		return $output;
	}
public static function uncomment_rfc822 ( $ string ) { $ string = ( string ) $ string ; $ position = 0 ; $ length = strlen ( $ string ) ; $ depth = 0 ; $ output = '' ; while ( $ position < $ length && ( $ pos = strpos ( $ string , '(' , $ position ) ) !== false ) { $ output .= substr ( $ string , $ position , $ pos - $ position ) ; $ position = $ pos + 1 ; if ( $ string [ $ pos - 1 ] !== '\\' ) { $ depth ++ ; while ( $ depth && $ position < $ length ) { $ position += strcspn ( $ string , '()' , $ position ) ; if ( $ string [ $ position - 1 ] === '\\' ) { $ position ++ ; continue ; } elseif ( isset ( $ string [ $ position ] ) ) { switch ( $ string [ $ position ] ) { case '(' : $ depth ++ ; break ; case ')' : $ depth -- ; break ; } $ position ++ ; } else { break ; } } } else { $ output .= '(' ; } } $ output .= substr ( $ string , $ position ) ; return $ output ; }
Remove RFC822 comments

@param string $data Data to strip comments from
@return string Comment stripped string
Remove RFC822 comments