Returns a binary data type of the string passed; data types other than string will first be converted to a string and then returned as binary data.
This function is useful if, for some reason, a string type actually contains binary data; using this function will ensure that all data in the string (even if it contains embedded nulls) is maintained in the binary object (Qore strings must normally be terminated by a single null, so some Qore string operations do not work on binary data with embedded nulls).
$bin = binary("hello");
Table 3.86. Arguments and Return Values for binary()
|
Argument Type |
Return Type |
Description |
|---|---|---|
|
A binary data type holding the string data passed. |
This function does not throw any exceptions.
Returns a string created from the binary data passed, taking an optional second argument giving the string encoding. If no second argument is passed then the default encoding is assumed.
No checking is performed for embedded null characters or for character encoding violations; the data is simply copied from the binary value to the string (with any embedded nulls, if present), and the string is tagged with the given encoding or with the default encoding if no second argument is passed. See also string() and binary().
string binary_to_string(binary $bin)
string binary_to_string(binary $bin, string $encoding)
$str = binary_to_string($bin, "utf8");
Table 3.87. Arguments and Return Values for binary_to_string()
Argument Type | Return Type | Description |
|---|---|---|
Returns a string corresponding to the binary data passed, taking an optional second argument giving the string encoding. If no second argument is passed then the default encoding is assumed. |
Converts the argument to a date and returns the date. When converting from an integer, the integer value represents the offset in seconds from 1970-01-01 in the local time zone.
See also date_ms(), date_us(), and localtime().
As of Qore 0.8.0, converting a date from a string is much more flexible; formats such as the following are now accepted (note that in the following examples, if the time zone/UTC offset is not explicitly specified, the local time zone is assumed):
Table 3.89. Examples Converting Date From String
String | Date |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$date = date(1); # return 1970-01-01T00:00:01
Table 3.90. Arguments and Return Values for date()
Argument Type | Return Type | Description |
|---|---|---|
Converts the argument to a date and returns the date. | ||
Converts the 1st argument to a date by the given conversion mask (2nd arg) and returns the date. Example: | ||
The argument is assumed to be the number of seconds since 1970-01-01 in the local time zone; this value is used to produce the date value that is returned. |
Table 3.91. String to Date conversion masks
Symbol | Description |
|---|---|
| Year's last two digits. The the current year's century is used for new date |
| Year with the all digits (length 4) like 1956, 0870, or ' 546' with space as the placeholder |
| Month number (length 2) like 11, 04, or ' 1' with space as the placeholder |
| Month name abbrevation (length 3) with the first letter uppercased. Example: |
| Month name abbrevation (length 3) with all letters uppercased. Example: |
| Date number (length 2) like 29, 04, or ' 1' with space as the placeholder |
| Minute number (length 2) like 11, 04, or ' 1' with space as the placeholder |
| Second number (length 2) like 11, 04, or ' 1' with space as the placeholder |
| Millisecond number (length 2) like 11, 04, or ' 1' with space as the placeholder |
This function does not throw any exceptions - except for date(string, string). It can throw DATE-CONVERT-ERROR exception.
Converts an object or a list to a hash; for any other argument, returns an empty hash (ignores any other arguments passed).
For an object argument, the hash returned is equal to the object members (excluding private members if called outside the class); a list is converted to a hash by taking even numbered list elements (starting with 0) and converting them to strings for the hash keys, and the odd numbered elements following the keys as the key value.
$h = hash($object); # creates a hash of the object's members
Table 3.93. Arguments and Return Values for hash()
Argument Type | Return Type | Description |
|---|---|---|
Returns a hash by taking the first list as a list of keys, and the second list as a list of values. If the two lists are of unequal sizes, then the keys list takes precedence (if the values list is longer, excess values are ignored). | ||
| Returns a hash by taking even numbered list elements (starting with 0) and converting them to strings for the hash keys, and the odd numbered elements following the keys as the key value. | |
| Returns the hash argument unmodified. | |
| Returns a hash of the object's members (public members only if called outside the class). | |
Returns an empty hash. |
This function does not throw any exceptions.
Converts the argument passed to a string value.
This function will not convert a binary value to a string; in order to do this, use the binary_to_string() function.
$str = string(200); # returns "200"
Table 3.96. Arguments and Return Values for string()
Argument Type | Return Type | Description |
|---|---|---|
Converts the argument passed to a string value. |
This function does not throw any exceptions.
Returns the data type of the argument passed. See Type Constants for the values returned by this function..
$type = type("hello"); # returns Type::String ("string")
Table 3.97. Arguments and Return Values for type()
Argument Type | Return Type | Description |
|---|---|---|
Returns the data type of the argument passed. See Type_Constants for the values that can be returned by this function. |
This function does not throw any exceptions.
deprecated: use type() instead.
typename(expression)
This function does not throw any exceptions.
This function will be removed in a future version of Qore.