@substr - Extract a Substring
The @substr directive in Ahmed PHP Template Engine is used to extract a portion of a string based on a starting position and optional length.
Syntax
@substr(variable, start, length)variable: The string to extract from.start: The position to begin extraction (0-based index).length(optional): The number of characters to extract.
Description
If
lengthis omitted, it extracts everything fromstartto the end of the string.Supports negative indices: a negative
startextracts from the end of the string.
Example
@define(text, "Hello, World!")
<p>@substr(text, 7, 5)</p>
<p>@substr(text, -6, 5)</p>Expected Output
Notes
Useful for manipulating strings dynamically within templates.
Negative
startcounts from the end of the string.If
lengthis longer than the remaining string, it extracts until the end.
Last updated