Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Crusher
- {
- protected static $conf = array();
- public function __construct ($requested_url = NULL, $query_string = NULL, $auth = NULL)
- {
- self::$conf = array(
- 'globals' => array(
- 'charset' => 'windows-1251',
- ),
- );
- }
- protected function ConvertRequestDataEncoding()
- {
- if(isset(self::$conf,self::$conf['globals'],self::$conf['globals']['charset']))
- {
- array_walk_recursive($_POST,array("self","callbackConvertEncoding"),self::$conf['globals']['charset']);
- array_walk_recursive($_GET,array("self","callbackConvertEncoding"),self::$conf['globals']['charset']);
- array_walk_recursive($_COOKIE,array("self","callbackConvertEncoding"),self::$conf['globals']['charset']);
- }
- $_REQUEST = array_merge($_POST,$_GET);
- $_REQUEST = array_merge($_REQUEST,$_COOKIE);
- }
- protected static function callbackConvertEncoding(&$item,&$key,$from_encoding)
- {
- $key = mb_convert_encoding($key,"UTF-8",$from_encoding);
- $item = mb_convert_encoding($item,"UTF-8",$from_encoding);
- if(!self::is_utf8($item))
- {
- $item = NULL;
- }
- if(!self::is_utf8($key))
- {
- $key= NULL;
- }
- return;
- }
- protected static function is_utf8($string) {
- // From http://w3.org/International/questions/qa-forms-utf-8.html
- return preg_match('%^(?:
- [\x09\x0A\x0D\x20-\x7E] # ASCII
- | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
- | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
- | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
- | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
- | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
- | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
- | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
- )*$%xs', $string);
- } // function is_utf8
- public function go()
- {
- if ( !empty($_POST) )
- {
- self::ConvertRequestDataEncoding();
- }
- }
- }
- header('Content-Type: text/html; charset=windows-1251');
- $crushme = new Crusher();
- $crushme->go();
- ?><!DOCTYPE html>
- <html>
- <head>
- <meta charset="windows-1251">
- <title>Crusher</title>
- </head>
- <body>
- <?php
- echo '<pre>', print_r($_REQUEST , 1), '</pre>';
- ?>
- <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
- <input name="form[content]" value="Я твой дом труба шатал" /><br/>
- <textarea rows="10" cols="40" name="form[ta]">Суспензия, как того требуют законы термодинамики, принципиально неизмерима.
- Возмущение плотности приводит к появлению упруго-пластичный тензиометр, хотя этот факт нуждается в дальнейшей тщательной экспериментальной проверке.
- Можно думать, что шурф полидисперсен. Конечно, нельзя не принять во внимание тот факт, что ил относительно отражает ташет
- в полном соответствии с законом Дарси</textarea><br/>
- <input type="submit" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement