substrReturn part of a string
&reftitle.description;
stringsubstrstringstringintoffsetintnulllength&null;
Returns the portion of string specified by the
offset and length parameters.
&reftitle.parameters;
string
The input string.
offset
If offset is non-negative, the returned string
will start at the offset'th position in
string, counting from zero. For instance,
in the string 'abcdef', the character at
position 0 is 'a', the
character at position 2 is
'c', and so forth.
If offset is negative, the returned string
will start at the offset'th character
from the end of string.
If string is less than
offset characters long, an empty string will be returned.
Using a negative offset
]]>
length
If length is given and is positive, the string
returned will contain at most length characters
beginning from offset (depending on the length of
string).
If length is given and is negative, then that many
characters will be omitted from the end of string
(after the start position has been calculated when a
offset is negative). If
offset denotes the position of this truncation or
beyond, an empty string will be returned.
If length is given and is 0,
an empty string will be returned.
If length is omitted or &null;, the substring starting from
offset until the end of the string will be
returned.
Using a negative length
]]>
&reftitle.returnvalues;
Returns the extracted part of string, or
an empty string.
&reftitle.changelog;
&Version;&Description;8.0.0length is nullable now.
When length is explicitly set to &null;,
the function returns a substring finishing at the end of the string, when it previously returned an empty string.
8.0.0
The function returns an empty string where it previously returned &false;.
&reftitle.examples;
Basic substr usage
]]>
substr casting behaviour
]]>
&example.outputs;
Invalid Character Range
If an invalid character range is requested, substr returns
an empty string as of PHP 8.0.0; previously, &false; was returned instead.
]]>
&example.outputs.8;
]
&example.outputs.7;
&reftitle.seealso;
strrchrsubstr_replacepreg_matchtrimmb_substrwordwrapString access and modification by character