Retrieves the byte position of a substring within a string.
intbindex(softstring$string, softstring$substring, softint$offset = 0)
$i = bindex("hello there", "the");Table 3.102. Arguments and Return Values for bindex()
Argument Type | Return Type | Description |
|---|---|---|
| If the substring is found, returns the byte position of the substring within the string (starting at 0). If not found, returns -1. If an offset position is given, the search starts at the offset position. All values are byte positions, not character positions, which may differ for multi-byte character encodings. |
This function does not throw any exceptions.
Returns the starting byte position of a string in another, starting from the end of the string (-1 if not found) and takes an optional starting position.
intbrindex(softstring$string, softstring$substring, softint$offset = -1)
$i = brindex("hello there", "the");Table 3.103. Arguments and Return Values for brindex()
Argument Type | Return Type | Description |
|---|---|---|
| Returns the starting byte position of a string in another, starting from the end of the string, or from |
This function does not throw any exceptions.
Removes the trailing end-of-line indicator ('\n' or '\r\n') from a string and returns the new string (also see the chomp operator). If no EOL indicator is present in the string, this function simply returns the original string unmodified. This function accepts variable references, in which case it will modify the string in place and also return the modified string.
$line = chomp("hello\n"); # returns "hello"Table 3.104. Arguments and Return Values for chomp()
Argument Type | Return Type | Description |
|---|---|---|
Returns the new string with any end-of-line character(s) removed. | ||
If the first argument is a variable reference and points to a string, then the string is modified in place and the new string is also returned. Otherwise if the reference is any other type, no action is taken and no value is returned. |
This function does not throw any exceptions.
Performs explicit string character encoding conversions.
$utf8_str = convert_encoding($iso_8859_1_str, "utf-8");
Table 3.107. Exceptions Thrown by convert_encoding()
err | desc |
|---|---|
| There was an error converting to the target encoding (ex: conversion not supported, illegal character sequence, etc). |
Decodes percent numeric codes in a URL string and returns the decoded string.
$decoded_url = decode_url($encoded_url);
This function does not throw any exceptions.
Returns the first string argument tagged with the character encoding given as the second argument; does not actually change the string data; use only in the case that a string is tagged with the wrong encoding, for example, if a string from a File object has a different encoding than the File object.
$utf8_str = force_encoding($bad_str, "utf-8");
This function does not throw any exceptions.
Returns a string describing the character encoding of the string passed.
$enc = get_encoding($string);
This function does not throw any exceptions.
Retrieves the character position of a substring within a string.
intindex(softstring$string, softstring$substring, softint$offset = 0) (CONST)
$i = index("hello there", "the");Table 3.111. Arguments and Return Values for index()
Argument Type | Return Type | Description |
|---|---|---|
| If the substring is found, returns the position of the substring within the string (starting at 0). If not found, returns -1. If an offset position is given, the search starts at the offset position. All values are character positions, not byte positions, which may differ for multi-byte character encodings. |
This function does not throw any exceptions.
Returns the length in characters for the string passed. Note that the byte length may differ from the character length with multi-byte character encodings. For byte length of a string, see strlen().
$len = length("hello"); # returns 5Table 3.113. Arguments and Return Values for length()
Argument Type | Return Type | Description |
|---|---|---|
Returns the length in characters for the string passed. | ||
Returns the number of bytes in the binary data passed. |
This function does not throw any exceptions.
Gives the numeric value of the given byte in the string passed (the first byte if no offset is passed); if no string is passed or the offset is after the end of the string, -1 is returned.
intord(softstring$string, softint$offset = 0) (CONST)
$i = ord("A"); # returns 65Table 3.114. Arguments and Return Values for ord()
Argument Type | Return Type | Description |
|---|---|---|
| Gives the numeric value of the given byte in the string passed (the first byte if no offset is passed); if no string is passed or the offset is after the end of the string, -1 is returned. |
This function does not throw any exceptions.
Table 3.115. Arguments and Return Values for regex()
Argument Type | Return Type | Description |
|---|---|---|
Returns |
Table 3.116. Exceptions Thrown by regex()
err | desc |
|---|---|
| There was an error compiling the regular expression. |
For more information on regular expression processing, see Regular Expressions.
Returns a list of substrings in a string based on matching patterns defined by a regular expression.
*listregex_extract(string$string, string$pattern, int$options = 0)
my *list $rv = regex_extract("hello:there", "(\\w+):(\\w+)");Table 3.117. Arguments and Return Values for regex_extract()
Argument Type | Return Type | Description |
|---|---|---|
Returns any patterns in parentheses in the second argument when applied tot he first argument as a |
Table 3.118. Exceptions Thrown by regex_extract()
err | desc |
|---|---|
| Invalid options were passed to the function. |
| There was an error compiling the regular expression. |
For more information on regular expression processing, see Regular Expressions.
Table 3.119. Arguments and Return Values for regex_subst()
Argument Type | Return Type | Description |
|---|---|---|
| Returns the result of applying the second argument as a pattern to the first argument, with the 3rd argument as the replacement string. The fourth argument can be used to set regex options; for valid options, see Regex Constants |
Table 3.120. Exceptions Thrown by regex_subst()
err | desc |
|---|---|
| Invalid options were passed to the function. |
| There was an error compiling the regular expression. |
For more information on regular expression processing, see Regular Expressions.
Returns the starting character position of a string in another, starting from the end of the string (-1 if not found) and takes an optional starting position.
intrindex(softstring$string, softstring$substring, softint$offset = -1) (CONST)
$i = rindex("hello there", "the");Table 3.122. Arguments and Return Values for rindex()
Argument Type | Return Type | Description |
|---|---|---|
| Returns the starting character position of a string in another, starting from the end of the string, or from the third argument giving the character (not byte) position if given (negative values are offsets from the end of the string, -1 gives the last character of the string). If the thirs argument is given, then the reverse search starts at that character position (searches always go from the end of the string toward the beginning). Returns -1 if the substring cannot be found. All values are character positions, not byte positions, which may differ for multi-byte character encodings. |
This function does not throw any exceptions.
Splits a string into a list of components based on a separator string. If the separator string is not found in the string to split, then a list with only one element containing the entire string argument is returned.
Only the version that takes the third argument as a quote string can throw exceptions.
listsplit(string$pattern, string$string, bool$with_pattern = False) (CONST)
listsplit(string$separator, string$string, string$quote) (RET_VALUE_ONLY)
my list $list = split(":", "some:text:here"); # returns ("some", "text", "here")Table 3.123. Arguments and Return Values for split()
Argument Type | Return Type | Description |
|---|---|---|
Returns a list of each component of a string separated by a separator string, with the separator removed; the separator pattern will not be included in the elements of the list returned unless the third argument is | ||
Returns a list of each component of a string separated by a separator string, with the separator removed; the quote character can appear as the first part of a field, in which case it is assumed to designate the entire field. If instances of the quote character are found in the field preceded by a backquote character (\), then these quote characters are ignored. Note that this variant of the function can throw exceptions if the quote character is found and not terminated, or if text other than the separator string follows an end quote. This is the only variant of split() that can throw exceptions. | ||
Returns a list of each component of thebinary object separated by the bytes identified by |
Table 3.124. Exceptions Thrown by split()
err | desc |
|---|---|
| End quote character not found or excess text found following separator string. |
Returns the length in bytes of the string argument. Note that the byte length may differ from the character length with multi-byte character encodings. For the character length of a string, see length().
$len = strlen("hello"); # returns 5Table 3.125. Arguments and Return Values for strlen()
Argument Type | Return Type | Description |
|---|---|---|
Returns the length of the string passed. If the argument is not a string, then it is converted to a string. |
This function does not throw any exceptions.
Returns new string with repeated original content with optionaly removed trailing characters.
my string $ret = strmul("hello", 2); # returns "hellohello"
my string $ret = strmul("%s,", 3, 1); # returns "%s,%s". See missing last ','
Table 3.126. Arguments and Return Values for strmul()
Argument Type | Return Type | Description |
|---|---|---|
| Returns the |
Table 3.127. Exceptions Thrown by strmul()
err | desc |
|---|---|
| Offset argument has to be 0 or greater than 0. |
| Multiple argument has to be greater than 0. |
Returns a portion of a string starting from an integer offset, with an optional length. Arguments can be negative, giving offsets from the end of the string. All offsets are character positions, not byte positions.
stringsubstr(softstring$string, softint$offset, softint$len) (CONST)
stringsubstr(softstring$string, softint$offset) (CONST)
$str = substr("hello there", 6); # returns "there"Table 3.128. Arguments and Return Values for substr()
Argument Type | Return Type | Description |
|---|---|---|
| Returns the substring according to the arguments. If |
This function does not throw any exceptions.
Removes characters from the start and end of a string and returns the new string (also see the trim operator). This function accepts variable references, in which case it will modify the string in place and also return the modified string.
By default (if the second argument is omitted or passed as an empty string) the following whitespace characters are removed: ' ', '\n', '\r', '\t', '\v' (vertical tab, ASCII 11), and '\0' (null character). To trim other characters, pass a string as the second argument specifying the characters to be removed.
stringtrim(string$string, string$chars = "") (CONST)
$line = trim(" hello \n"); # returns "hello"Table 3.131. Arguments and Return Values for trim()
Argument Type | Return Type | Description |
|---|---|---|
Returns the new string with characters removed from the beginning and end of the string; if the second argument is given then it defines the characters to be removed, otherwise whitespace is removed. | ||
If the reference points to a string, the string is trimmed in place and the result is also returned; if the second argument is given then it defines the characters to be removed, otherwise whitespace is removed. If the reference is not a string then no value is returned. |
This function does not throw any exceptions.
There are no comments yet