Translates the given string into a boolean value if it's in the proper format

@param string $string The string to convert

@return boolean true or false, translated
@throws Exception if string cannot be converted
545595
public static function strToBool($string)
    {
        if(is_bool($string))
            return $string;

        if (in_array(strtolower((string)$string), array('1', 'true', 'on', '+', 'yes', 'y')))
            return true;
        elseif (in_array(strtolower((string)$string), array('', '0','false', 'off', '-', 'no', 'n')))
            return false;

        return false;
    }
865299
public static function validate($string)
    {
        try {
            if (is_numeric($string) && (int)$string == $string) {
                $date = new DateTime('@' . $string);
            } else {
                $date = self::parse($string);
            }
        } catch (Exception $ex) {
            return false;
        }

        // String is empty or not a valid date
        if (empty($string) || $date === false) {
            return false;

            // String is a valid date
        } else {
            return true;
        }
    }
445175
public function convert($string, $target)
    {
        $ok_methods = [self::CONVERT_TO_LC, self::CONVERT_TO_ND, self::CONVERT_TO_LCND];

        if (!in_array($target, $ok_methods)) {
            throw new Exception_InvalidArgument(
                sprintf('Invalid argument 2 "%s", valid values are [%s].'
                    , $target
                    , implode('|', $ok_methods)
                )
            );
        }
        if (function_exists('phrasea_utf8_convert_to')) {
            return phrasea_utf8_convert_to($string, $target);
        }

        $out = '';
        $_map = $this->getMap($target);   // faster in loop
        $length = mb_strlen($string, 'UTF-8');

        for ($i = 0; $i < $length; $i++) {
            if (true === array_key_exists(($c = mb_substr($string, $i, 1, 'UTF-8')), $_map)) {
                $out .= $_map[$c];
            } else {
                $out .= $c;
            }
        }

        return $out;
    }
1141305
protected function translate($string)
    {
        $translated = $this->app['translator']->get($string);

        return is_string($translated) ? $translated : $string;
    }
422639
public function transform($string)
    {
        $string = Normalizer::normalize($string, $this->form);
        if ($string === null) {
            throw new UnexpectedValueException('Normalizer error.');
        }
        return $string;
    }
1035634
public static function convertEncoding($string)
    {
        $to     = 'UTF-8';
        $from   = self::WEB_SERVICE_CHARSET;
        $str = false;
        
        if (function_exists('iconv')) {
            $str = iconv($from, $to . '//TRANSLIT', $string);
        } elseif (function_exists('mb_convert_encoding')) {
            $str = mb_convert_encoding($string, $to, $from);
        }

        if ($str === false) {
            $str = $string;
        }

        return $str;
    }
507792
public function iShouldGet(PyStringNode $string)
    {
        if ($this->getOutput() != trim($string->getRaw())) {
            throw new \Exception(
                "Actual output is:\n" . $this->getOutput()
            );
        }
    }
1373331
protected function translit($string)
    {
        $stringOutput = (@iconv('UTF-8', 'ASCII//TRANSLIT', $string));
        if ($stringOutput === false) {
            $string = preg_replace('!([^0-9a-zA-Z\.,:;()/-_\s])!', '', $string); // use more explicit statement, alphanum dont do the job
            $stringOutput = (@iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $string));
            if ($stringOutput === false) {
                throw new \Exception('Cant convert '.$string);
            }
        }

        return $stringOutput;
    }
69112
function _convertString($string)
	{
		// chop away beggining and ending quotes
		$string = substr($string, 1, strlen($string) - 2);
		if (strlen($string) > 255) {
			throw new PHPExcel_Writer_Exception("String is too long");
		}

		return pack('C', $this->ptg['ptgStr']) . PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($string);
	}
900356
public static function isSerialized($string)
    {
        // Set Handle
        set_error_handler(function () {
        }, E_ALL);
        $result = unserialize($string);
        // Restores the previous error handler function
        restore_error_handler();
        return !($result === false);
    }
67019
public static function decode($string)
    {
        return ($string === self::NULL) ? null : strtr($string, self::$decodeMap);
    }
171364
static public function parseString( $string ){
		if( substr_count( $string, "{" ) !== substr_count( $string, "}" ) )							//  
			throw Exception( 'Invalid paranthesis' );
		$string	= preg_replace( '/\/\*.+\*\//sU', '', $string );
		$string	= preg_replace( '/(\t|\r|\n)/s', '', $string );
		$state	= (int) ( $buffer = $key = '' );
		$sheet	= new ADT_CSS_Sheet();
		for( $i=0; $i<strlen( $string ); $i++ ){
			$char = $string[$i];
			if( !$state && $char == '{' ){
				$state	= (boolean) ( $key = trim( $buffer ) );
				$buffer	= '';
			}
			else if( $state && $char == '}' ){
				$properties	= self::parseProperties( $buffer );
				foreach( explode( ',', $key ) as $selector )
					$sheet->addRule( new ADT_CSS_Rule( $selector, $properties ) );
				$state	= (boolean) ($buffer = '');
			}
			else
				$buffer	.= $char;
		}
		return $sheet;
	}
484206
protected function getCorrectType($string)
    {
        if (!is_string($string)) {
            return $string;
        }

        switch (strtolower($string)) {
            case 'true':
                return true;
            case 'false':
                return false;
            case 'null':
                return null;
        }

        if (is_numeric($string)) {
            return (int)$string;
        }

        return $string;
    }
232491
public function write($string) : int
	{
		if (! \is_resource($this->resource))
		{
			throw new Exception\UnwritableStreamException('Stream is not resourceable');
		}

		if (! $this->isWritable())
		{
			throw new Exception\UnwritableStreamException('Stream is not writable');
		}

		$result = \fwrite($this->resource, $string);

		if (false === $result)
		{
			throw new Exception\UnwritableStreamException('Unable to write to the stream');
		}

		return $result;
	}
707172
protected static function _parse($string) {
		if (substr_count($string, '::') !== 2) {
			throw new Exception('Possible data tampering: form signature string has wrong format.');
		}
		list($locked, $excluded) = explode('::', $string, 3);

		return [
			'locked' => unserialize(urldecode($locked)),
			'excluded' => unserialize(urldecode($excluded))
		];
	}
1255477
public static function isUTF8String($string)
  { 
    $sample = @iconv('utf-8', 'utf-8', $string);
    
    if (md5($sample) == md5($string))
      return true;
    else
      return false;
  }
966845
public static function stringToValue($string)
	{
		if($string == '')
		{
			return $string;
		}
		if(is_float($string))
		{
			return (float) $string;
		}
		if(is_int($string))
		{
			return (int) $string;
		}
		if(strtolower($string) == 'true')
		{
			return true;
		}
		if(strtolower($string) == 'false')
		{
			return false;
		}
		if(strtolower($string) == 'null')
		{
			return NULL;
		}
		
		return $string;
	}