====== substr ====== ~~NOTOC~~ **From Version 5.21.0-beta-2** == Syntax == string substr( string $fieldName, int $startPoint, optional int $length ) ===== Description ===== The method ''substr()'' creates an SQL statement that returns the substring of a specified string field. ===== Parameters ===== ==== $fieldName ==== The fieldname to be substringed. The fieldname must be accessible as part of the current SQL statement. ==== $startPoint ==== The starting point within the original string for the substring to begin. Offsets in SQL statements are 1 based, rather than the normal 0 (Zero) based offsets used in PHP. ==== $length ==== If specified, the length of the string to return. If not specified, then the remainder of the string starting at the start point is returned ===== Usage ===== /* * To return the an associative array of codes plus * the first 20 characters of a description. */ $sql = "SELECT code, {$db->substr('description',1,20)} FROM some_table"; $data = $db->getAssoc($sql); ===== Negative Offsets ===== Not all databases support the use of negative offsets (to return values based on the end of the string), so use in portable applications is not recommended.