Encode data

@param  mixed  $data
@return string
545778
static public function encode($data)
	{
	    if (is_string($data)) {
	        $data = str_replace(array("\r\n"), "", $data);
	        if (strpos($data, '{') ===0 || strpos($data, '[') ===0) {
	            $data = json_decode($data, true);
	        }
	    }
	    
		return json_encode($data);
	}
24034
public static function encode($data)
    {
        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
            $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        } else {
            $json = json_encode($data);
        }

        self::handleError(json_last_error());

        return $json;
    }
949763
private function encrypt($data)
	{
		$key = $this->_config['appSecret'];
		// encrypt
		$key    =   md5($key);
	    $x      =   0;
	    $len    =   strlen($data);
	    $l      =   strlen($key);
	    for ($i = 0; $i < $len; $i++)
	    {
	        if ($x == $l) 
	        {
	            $x = 0;
	        }
	        $char .= $key{$x};
	        $x++;
	    }
	    for ($i = 0; $i < $len; $i++)
	    {
	        $str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);
	    }
	    return base64_encode($str);
	}
456479
public function serializeData($data) {
		if(is_array($data)) {
			ksort($data);
			$return = '';
			foreach($data as $key => $value) {
				if(is_numeric($key)) {
					$return .= $this->serializeData($value);
				} else {
					$return .= $key . $this->serializeData($value);
				}
			}
			return $return;
		} else {
			return (string)$data;
		}
	}
593999
public function encode(string $event, $data)
    {
        $packet = Packet::MESSAGE . Packet::EVENT;
        $shouldEncode = is_array($data) || is_object($data);
        $data = $shouldEncode ? json_encode($data) : $data;
        $format = $shouldEncode ? '["%s",%s]' : '["%s","%s"]';

        return $packet . sprintf($format, $event, $data);
    }
603023
public function encode($data)
    {
        $data['exp'] = time() + $this->lifeTime;

       return JWT::encode($data, $this->secretKey);
    }
420957
public static function decodeData($data)
    {
        if (\is_array($data)) {
            foreach ($data as $key => $value) {
                $data[$key] = \urldecode($value);
            }

            return $data;
        }

        return \urldecode($data);
    }
1035789
protected static function loopDecode($data)
    {
        if (is_array($data)) {
            foreach ($data as &$value) {
                $value = self::loopDecode($value);
            }
        } elseif (is_object($data)) {
            return self::loopDecode((array) $data);
        }
        return $data;
    }
1087833
public function encode($data)
    {
        // skip empty strings
        if ($data === '') {
            return '""';
        }

        $data = json_encode($data, $this->options['flags'], $this->options['depth']);
        if (json_last_error() > 0) {
            $data = null;
            $this->error = json_last_error_msg() ?: 'Unknown';
        }

        return $data;
    }
80647
final private static function encodeString(string $data): string
    {
        $buf = '';
        self::encodeUnsigned($buf, strlen($data));
        return $buf . $data;
    }
152046
public static function encode($data)
    {
        $module = $data['module'];
        $interface = $data['interface'];
        $cost_time = $data['cost_time'];
        $success = $data['success'];
        $code = isset($data['code']) ? $data['code'] : 0;
        $msg = isset($data['msg']) ? $data['msg'] : '';
        
        // 防止模块名过长
        if(strlen($module) > self::MAX_CHAR_VALUE)
        {
            $module = substr($module, 0, self::MAX_CHAR_VALUE);
        }

        // 防止接口名过长
        if(strlen($interface) > self::MAX_CHAR_VALUE)
        {
            $interface = substr($interface, 0, self::MAX_CHAR_VALUE);
        }

        // 防止msg过长
        $module_name_length = strlen($module);
        $interface_name_length = strlen($interface);
        $avalible_size = self::MAX_UDP_PACKGE_SIZE - self::PACKAGE_FIXED_LENGTH - $module_name_length - $interface_name_length;
        if(strlen($msg) > $avalible_size)
        {
            $msg = substr($msg, 0, $avalible_size);
        }

        // 打包
        return pack('CCfCNnN', $module_name_length, $interface_name_length, $cost_time, $success ? 1 : 0, $code, strlen($msg), time()).$module.$interface.$msg;
    }
1352776
function encryptSimple($data) {
		$result = '';
		for($i=0; $i<strlen($data); $i++) {
			$char = substr($data, $i, 1);
			$keychar = substr($this->encPassword, ($i % strlen($this->encPassword))-1, 1);
			$char = chr(ord($char)+ord($keychar));
			$result.=$char;
		}
		return str_replace(array('+', '/'), array('-', '_'),base64_encode($result));
	}
319093
protected function convertEncoding($data)
    {
        if (!$this->shouldConvert) {
            return $data;
        }
        return $this->stringConverter->convert("$data", 'utf-8', $this->getOption(self::ENCODING));
    }
715757
public static function encode($data, $pad = null) {
		$str = str_replace(array('+', '/'), array('-', '_'), base64_encode($data));
		if (!$pad) {
			$str = rtrim($str, '=');
		}
		return $str;
	}
904645
private function encodeList(array $data = null)
    {
        $data = is_null($data) ? $this->data : $data;

        $list = "";
        foreach ($data as $value) {
            $list .= $this->doEncode($value);
        }

        return "l{$list}e";
    }
754169
public function encode($data)
    {

        // Convert the data to a binary string.
        $bits = '';
        foreach (str_split($data) as $char) {
            $bits .= sprintf('%08b', ord($char));
        }

        // Make sure the string length is a multiple of 5, padding if needed.
        $len = strlen($bits);
        $mod = $len % 5;
        if ($mod !== 0) {
            $bits = str_pad($bits, $len + 5 - $mod, '0', STR_PAD_RIGHT);
        }

        // Split the binary string into 5-bit chunks and encode each chunk.
        $output = '';
        foreach (str_split($bits, 5) as $chunk) {
            $output .= substr($this->getConfig('alphabet'), bindec($chunk), 1);
        }

        return $output;

    }
289559
public function encode($data): string
    {
        $encoded = \json_encode($data, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
        if (\json_last_error() !== JSON_ERROR_NONE) {
            throw new EncodingException(\json_last_error_msg());
        }
        return $encoded;
    }