Core Function UUDecode
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> UUDecode( <expression> ) </pre> === Description === Decodes a string that was encode using the uuencode algorithm . === Parameters === ==== expression ==== The data to...") |
m (1 revision) |
||
(2 intermediate revisions by one user not shown) | |||
Line 80: | Line 80: | ||
echo "Decoded Perl: $DecodedPerl\n"; | echo "Decoded Perl: $DecodedPerl\n"; | ||
# Prints: Decoded Perl: Testy | # Prints: Decoded Perl: Testy | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Using Unicode | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | $Str = "Testy ehehe XD!こんにちは"; | ||
+ | $PerlEncoded = PerlUUEncode($Str); | ||
+ | $PHPEncoded = UUEncode($Str); | ||
+ | echo "Encoded Perl: $PerlEncoded\n"; | ||
+ | echo "Encoded PHP: $PHPEncoded\n"; | ||
+ | my $DecodedPerl = PerlUUDecode($PerlEncoded); | ||
+ | echo "Decoded Perl: $DecodedPerl\n"; | ||
+ | msgbox $DecodedPerl; | ||
+ | |||
+ | Function PerlUUEncode ( $str ) | ||
+ | { | ||
+ | return (string)pack("u", $str); | ||
+ | } | ||
+ | |||
+ | Function PerlUUDecode ( $str ) | ||
+ | { | ||
+ | return unpack("u", $str, 3); | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
UUDecode( <expression> )
Contents |
Description
Decodes a string that was encode using the uuencode algorithm .
Parameters
expression
The data to be encoded.
Can be a string or binary variable.
If it is neither of the above it will be converted into a string and used anyway.
Return Value
Success: Returns the uuencoded data.
Failure: Returns empty string.
Remarks
This function produces results that are equal to PHPs.
If you require results equal to Perl try the UUEncode found on the Pack( ) function.
Example
my $Encoded = UUEncode("Testy"); echo "Encoded: $Encoded\n"; my $Decoded = UUDecode($Encoded); echo "Decoded: $Decoded\n"; # Prints # Encoded: %5&5S='D` # ` # # Decoded: Testy
Perl compatible UUEncode a string
my $Encoded = PerlUUEncode("Testy"); echo "Encoded: $Encoded\n"; my $Decoded = PerlUUDecode($Encoded); echo "Decoded: $Decoded\n"; # Prints # Encoded: %5&5S='D` # # Decoded: Testy Function PerlUUEncode ( $str ) { return (string)pack("u", $str); } Function PerlUUDecode ( $str ) { return unpack("u", $str, 3); } # Notice this Perl compatible one produces a slightly # different text to the one above? Of course both are # valid and Unpack() will read both the Perl/PHP styles # with no problem # Here we see unpack() can decode PHP uuencoded strings $PHPEncoded = UUEncode("Testy"); my $DecodedPHP = PerlUUDecode($PHPEncoded); echo "Decoded PHP: $DecodedPHP\n"; # Prints: Decoded PHP: Testy # Here we see UUDecode() can handle Perl encoded ones $PerlEncoded = PerlUUEncode("Testy"); my $DecodedPerl = UUDecode($PerlEncoded); echo "Decoded Perl: $DecodedPerl\n"; # Prints: Decoded Perl: Testy
Using Unicode
$Str = "Testy ehehe XD!こんにちは"; $PerlEncoded = PerlUUEncode($Str); $PHPEncoded = UUEncode($Str); echo "Encoded Perl: $PerlEncoded\n"; echo "Encoded PHP: $PHPEncoded\n"; my $DecodedPerl = PerlUUDecode($PerlEncoded); echo "Decoded Perl: $DecodedPerl\n"; msgbox $DecodedPerl; Function PerlUUEncode ( $str ) { return (string)pack("u", $str); } Function PerlUUDecode ( $str ) { return unpack("u", $str, 3); }