Lines Matching defs:length
72 * Return part of a string given character offset (and optionally length)
76 * @param int $length (optional) length in UTF-8 characters from offset
82 public static function substr($str, $offset, $length = null)
85 if ($length === null) {
89 return mb_substr($str, $offset, $length);
97 * offset and length, we'll repeat a group of 65535 characters when needed (ok, up to MAXINT-65536)
99 * substr documentation states false can be returned in some cases (e.g. offset > string length)
103 * we only carry it out when necessary. It isn't necessary for +ve offsets and no specified length
109 if ($length !== null) $length = (int)$length;
112 if ($length === 0) return '';
113 if ($offset < 0 && $length < 0 && $length < $offset) return '';
125 // establish a pattern for offset, a non-captured group equal in length to offset
136 // establish a pattern for length
137 if ($length === null) {
143 if ($length > 0) {
144 // reduce any length that would go past the end of the string
145 $length = min($strlen - $offset, $length);
146 $Lx = (int)($length / 65535);
147 $Ly = $length % 65535;
148 // +ve length requires ... a captured group of length characters
151 } elseif ($length < 0) {
152 if ($length < ($offset - $strlen)) return '';
153 $Lx = (int)((-$length) / 65535);
154 $Ly = (-$length) % 65535;
155 // -ve length requires ... capture everything except a group of -length characters
173 * @param int $length If given and is positive, it represents the length of the portion of string which is
174 * to be replaced. If length is zero then this function will have the effect of inserting
181 public static function substr_replace($string, $replacement, $start, $length = 0)
186 $ret .= self::substr($string, $start + $length);
357 $length = null;
359 while ($length === null || $length < $offset) {
365 $length = self::strlen(substr($haystack, 0, $pos));
367 if ($length < $offset)
368 $comp = $pos - $length;
371 return $length;