<"); private static $inst = null; private static function getInstance() { if(is_null(self::$inst)) { self::$inst = new self(); } return self::$inst; } private function run($isEncode = false) { $out = ''; if($this->string) { $dict = $isEncode ? $this->english : $this->leet; $dict_ = $isEncode ? $this->leet : $this->english; $flippedDict = array_flip($dict); // for good performance for($i = 0; $i < strlen($this->string); $i++) { $char = $this->string[$i]; $out .= isset($flippedDict[$char]) ? $dict_[$flippedDict[$char]] : $char; } } return $out; } public function setString($string) { $t = self::getInstance(); $t->string = $string; return $t; } public static function encode($string) { return self::getInstance()->setString($string)->run(true); } public static function decode($string) { return self::getInstance()->setString($string)->run(); } }