encode

@param mixed $value
@param string $name
@return string
968519
public function encode($value, $name)
    {
        if ($this->isDynamicArray($name)) {
            $length = count($value);
            $nestedName = $this->nestedName($name);
            $result = [];
            $result[] = IntegerFormatter::format($length);

            foreach ($value as $val) {
                $result[] = $this->encode($val, $nestedName);
            }
            return $result;
        } elseif ($this->isStaticArray($name)) {
            $length = $this->staticArrayLength($name);
            $nestedName = $this->nestedName($name);
            $result = [];

            foreach ($value as $val) {
                $result[] = $this->encode($val, $nestedName);
            }
            return $result;
        }
        return $this->inputFormat($value, $name);
    }
1092888
public static function ConvertEncoding($value, $to, $from)
	{
		if (self::getIsMbstringEnabled()) {
			$value = mb_convert_encoding($value, $to, $from);
			return $value;
		}

		if (self::getIsIconvEnabled()) {
			$value = iconv($from, $to, $value);
			return $value;
		}

		// else, no conversion
		return $value;
	}
865785
public final function header(string $name, string $value = null)
    {
        return ($value === null) ? $this->getHeader($name) : $this->setHeader($name, $value);
    }
1093272
protected function phpJsonEncodeNameValue( $name, $value )
    {
        return (sprintf("%s:%s", $this->phpJsonEncode(strval($name)), $this->phpJsonEncode($value)));
    }
368783
public function encodeValue($value)
    {
        if (is_bool($value)) {
            return (int) $value;
        }

        if ($value instanceof Enum) {
            return $value->name();
        }

        if ($value instanceof Stream) {
            return json_encode($value->__toString());
        }

        return json_encode($value);
    }
166345
public static function encode($value, int $options = null) : string
    {
        if ($options) {
            $encoded = json_encode($value, $options);
        } else {
            $encoded = json_encode($value);
        }

        if (!is_string($encoded)) {
            throw new \InvalidArgumentException(sprintf(
                "Json encode failed (%s) with '%s' and type '%s'",
                json_last_error(),
                json_last_error_msg(),
                gettype($encoded)
            ));
        }

        return $encoded;
    }
85301
private function encodeNonTranslatableCharacters(string $value): string
    {
        return str_replace(
            array_keys($this->nonTranslatableCharactersHashMap),
            array_values($this->nonTranslatableCharactersHashMap),
            $value
        );
    }
424245
static public function urlencode($value)
    {
        if (is_string($value)) {
            return urlencode($value);
        } elseif (is_array($value)) {
            foreach ($value as $k => $v) {
                $value[$k] = static::urlencode($v);
            }
        }
        return $value;
    }
1317601
public function inputFormat($value, $name)
    {
        $value = (string) $value;

        if (Utils::isAddress($value)) {
            $value = mb_strtolower($value);

            if (Utils::isZeroPrefixed($value)) {
                $value = Utils::stripZero($value);
            }
        }
        $value = IntegerFormatter::format($value);

        return $value;
    }
1260366
private static function encodeValueXml($value)
    {
        if ($value instanceof \DateTime) {
            return $value->format('Y-m-d\TH:i:s.000\Z');
        }
        else if (is_bool($value)){
            return $value ? 'true' : 'false';
        } else {
            return $value;
        }
    }
73319
public static function encodeJsVar( $value ) {
		if( is_bool( $value ) ) {
			$s = $value ? 'true' : 'false';
		} elseif( is_null( $value ) ) {
			$s = 'null';
		} elseif( is_int( $value ) ) {
			$s = $value;
		} elseif( is_array( $value ) && // Make sure it's not associative.
				  array_keys( $value ) === range( 0, count( $value ) - 1 ) ||
				  count( $value ) == 0
		) {
			$s = '[';
			foreach( $value as $elt ){
				if( $s != '[' ) {
					$s .= ', ';
				}
				$s .= self::encodeJsVar( $elt );
			}
			$s .= ']';
		} elseif( is_object( $value ) || is_array( $value ) ) {
			// Objects and associative arrays
			$s = '{';
			foreach( (array)$value as $name => $elt ){
				if( $s != '{' ) {
					$s .= ', ';
				}
				$s .= '"' . self::escapeJsString( $name ) . '": ' .
					  self::encodeJsVar( $elt );
			}
			$s .= '}';
		} else {
			$s = '"' . self::escapeJsString( $value ) . '"';
		}
		return $s;
	}
158949
protected function encodeNotArray($value)
    {
        $value = (string) $value;
        $value = trim($value);
        $value = str_replace("\n", "\n\t", $value);

        return "\n\t{$value}\n";
    }
370011
private function encodeQuery(string $value): string
    {
        return preg_replace_callback(
            '/(?:[^'.self::UNRESERVED.self::SUB_DELIMS.':@%~\/\[\]\?]+|%(?![A-Fa-f0-9]{2}))/',
            function (array $match) {
                return rawurlencode($match[0]);
            },
            $value
        );
    }
890953
protected static function _encodeValue($value)
    {
        $string = '';

        switch (gettype($value))
        {
            case 'integer':
            case 'double':
                $string = $value;
                break;

            case 'boolean':
                $string = $value ? 'true' : 'false';
                break;

            case 'string':
                // Sanitize any CRLF characters..
                $string = '"' . str_replace(array("\r\n", "\n"), '\\n', $value) . '"';
                break;
        }

        return $string;
    }
262220
private static void encodeHeader(CharSequence name, CharSequence value, ByteBuf buf) {
        final int nameLen = name.length();
        final int valueLen = value.length();
        final int entryLen = nameLen + valueLen + 4;
        buf.ensureWritable(entryLen);
        int offset = buf.writerIndex();
        writeAscii(buf, offset, name, nameLen);
        offset += nameLen;
        buf.setByte(offset++, ':');
        buf.setByte(offset++, ' ');
        writeAscii(buf, offset, value, valueLen);
        offset += valueLen;
        buf.setByte(offset++, '\r');
        buf.setByte(offset++, '\n');
        buf.writerIndex(offset);
    }
1370046
protected function _encodeHeader($value)
    {
        if (Zend_Mime::isPrintable($value) === false) {
            if ($this->getHeaderEncoding() === Zend_Mime::ENCODING_QUOTEDPRINTABLE) {
                $value = Zend_Mime::encodeQuotedPrintableHeader($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND);
            } else {
                $value = Zend_Mime::encodeBase64Header($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND);
            }
        }

        return $value;
    }
1253091
private static function getHtmlAttribute(string $name, $value): string
    {
        if (!self::isset($value)) {
            return '';
        }

        if ($value === true) {
            return $name;
        }

        if (is_array($value)) {
            $value = self::convertAttributeArrayValue($name, $value);
        }

        return sprintf('%s="%s"', $name, static::escape((string) $value));
    }