1<?php 2class DataFilterEncoding extends DataFilter { 3 function DataFilterEncoding($encoding) { 4 $this->encoding = $encoding; 5 } 6 7 function getEncoding() { 8 return $this->encoding; 9 } 10 11 function process(&$data) { 12 // Remove control symbols if any 13 $data->set_content(preg_replace('/[\x00-\x07]/', "", $data->get_content())); 14 15 if (empty($this->encoding)) { 16 $encoding = $data->detect_encoding(); 17 18 if (is_null($encoding)) { 19 $encoding = DEFAULT_ENCODING; 20 }; 21 $converter = Converter::create(); 22 $data->set_content($converter->to_utf8($data->get_content(), $encoding)); 23 } else { 24 $converter = Converter::create(); 25 $data->set_content($converter->to_utf8($data->get_content(), $this->encoding)); 26 }; 27 28 return $data; 29 } 30 31 function _convert(&$data, $encoding) { 32 error_no_method('_convert', get_class($this)); 33 } 34} 35?>