*/ class Utf8Encoder extends Converter { protected $started = false; protected $from_encoding; protected $encoding_converter; protected $convert_html_entities = false; function __construct($from_encoding = null , $convert_html_entities = false) { $this->from_encoding = $from_encoding ? $from_encoding : Encoding::system(); $this->encoding_converter = EncodingConverter::create($this->from_encoding, Utf8::NAME); $this->convert_html_entities = $convert_html_entities; $this->reset(); } function from_encoding() { return $this->from_encoding; } function to_encoding() { return Utf8::NAME; } function get_convert_html_entities() { return $this->convert_html_entities; } function reset() { $this->started = false; } function convert($string) { if ($this->convert_html_entities) { $string = html_entity_decode($string, ENT_COMPAT, Utf8::NAME); } $string = $this->encoding_converter->convert($string); if (!$this->started) { $this->started = true; $string = Utf8::BOM . $string; } return $string; } }