protected function toUtf8($string)
    {
        if ($this->getEncoding() === 'utf-8') {
            $result = $string;
        } else {
            $result = $this->convertEncoding($string, 'UTF-8', $this->getEncoding());
        }

        if (! $this->isUtf8($result)) {
            throw new Exception\RuntimeException(
                sprintf('String to be escaped was not valid UTF-8 or could not be converted: %s', $result)
            );
        }

        return $result;
    }
protected function toUtf8($string)
    {
        if ($this->getEncoding() === 'utf-8') {
            $result = $string;
        } else {
            $result = $this->convertEncoding($string, 'UTF-8', $this->getEncoding());
        }

        if (! $this->isUtf8($result)) {
            throw new Exception\RuntimeException(
                sprintf('String to be escaped was not valid UTF-8 or could not be converted: %s', $result)
            );
        }

        return $result;
    }
protected function toUtf8 ( $ string ) { if ( $ this -> getEncoding ( ) === 'utf-8' ) { $ result = $ string ; } else { $ result = $ this -> convertEncoding ( $ string , 'UTF-8' , $ this -> getEncoding ( ) ) ; } if ( ! $ this -> isUtf8 ( $ result ) ) { throw new Exception \ RuntimeException ( sprintf ( 'String to be escaped was not valid UTF-8 or could not be converted: %s' , $ result ) ) ; } return $ result ; }
Converts a string to UTF-8 from the base encoding. The base encoding is set via this
class' constructor.

@param string $string
@throws Exception\RuntimeException
@return string
Converts a string to UTF - 8 from the base encoding . The base encoding is set via this class constructor .