Core Function BinaryFromStr
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> BinaryFromStr( <string> ) </pre> === Description === Returns a new binary variable created from a strings raw bytes === Parameters === ==== string ==== The string to ...") |
m (1 revision) |
||
(7 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | BinaryFromStr( <string> ) | + | BinaryFromStr( <string>, <flag> ) |
</pre> | </pre> | ||
Line 12: | Line 12: | ||
The string to use. | The string to use. | ||
+ | |||
+ | ==== flag ==== | ||
+ | |||
+ | Optional; Encoding to use. | ||
+ | |||
+ | Choices are: | ||
+ | |||
+ | "RAW" = Forces each character in the string to become a byte regardless of if the character contains a number higher than a byte (casts it) | ||
+ | |||
+ | "ASCII" | ||
+ | |||
+ | "UNICODE" = Alias to UTF8 (or whatever Sputnik is using for Unicode strings) | ||
+ | |||
+ | "UTF8" | ||
+ | |||
+ | "UTF7" | ||
+ | |||
+ | "UTF32" | ||
+ | |||
+ | Default: "RAW" | ||
=== Return Value === | === Return Value === | ||
Line 22: | Line 42: | ||
=== Example === | === Example === | ||
+ | |||
+ | |||
+ | ASCII Example | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $binary = Pack(" | + | $binary = Pack("A*", "Hello World!"); |
− | + | ||
− | + | ||
− | + | ||
$binStr = BinaryToStr($binary); | $binStr = BinaryToStr($binary); | ||
echo "String Content: $binStr\n"; | echo "String Content: $binStr\n"; | ||
− | + | // Prints: | |
− | + | // String Content: Hello World! | |
− | + | </syntaxhighlight> | |
− | / | + | |
− | Prints: | + | UNICODE (UTF8) Example |
− | + | ||
− | + | <syntaxhighlight lang="sputnik"> | |
− | + | $binary = BinaryFromStr("ふふふ", "UTF8"); | |
− | + | printr $binary; | |
− | + | $binStr = BinaryToStr($binary, "UTF8"); | |
− | + | echo "String Content: $binStr\n"; | |
− | + | // Prints: | |
− | + | // String Content: ふふふ | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | String Content: | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
BinaryFromStr( <string>, <flag> )
Contents |
Description
Returns a new binary variable created from a strings raw bytes
Parameters
string
The string to use.
flag
Optional; Encoding to use.
Choices are:
"RAW" = Forces each character in the string to become a byte regardless of if the character contains a number higher than a byte (casts it)
"ASCII"
"UNICODE" = Alias to UTF8 (or whatever Sputnik is using for Unicode strings)
"UTF8"
"UTF7"
"UTF32"
Default: "RAW"
Return Value
Returns a new binary variable created from a strings raw bytes
Remarks
None.
Example
ASCII Example
$binary = Pack("A*", "Hello World!"); $binStr = BinaryToStr($binary); echo "String Content: $binStr\n"; // Prints: // String Content: Hello World!
UNICODE (UTF8) Example
$binary = BinaryFromStr("ふふふ", "UTF8"); printr $binary; $binStr = BinaryToStr($binary, "UTF8"); echo "String Content: $binStr\n"; // Prints: // String Content: ふふふ