| @@ 278-287 (lines=10) @@ | ||
| 275 | * |
|
| 276 | * @return Stringy Object with a trimmed $str |
|
| 277 | */ |
|
| 278 | public function trim($chars = null) |
|
| 279 | { |
|
| 280 | if (!$chars) { |
|
| 281 | $chars = '[:space:]'; |
|
| 282 | } else { |
|
| 283 | $chars = preg_quote($chars, '/'); |
|
| 284 | } |
|
| 285 | ||
| 286 | return $this->regexReplace("^[$chars]+|[$chars]+\$", ''); |
|
| 287 | } |
|
| 288 | ||
| 289 | /** |
|
| 290 | * Replaces all occurrences of $pattern in $str by $replacement. |
|
| @@ 2025-2034 (lines=10) @@ | ||
| 2022 | * |
|
| 2023 | * @return Stringy Object with a trimmed $str |
|
| 2024 | */ |
|
| 2025 | public function trimLeft($chars = null) |
|
| 2026 | { |
|
| 2027 | if (!$chars) { |
|
| 2028 | $chars = '[:space:]'; |
|
| 2029 | } else { |
|
| 2030 | $chars = preg_quote($chars, '/'); |
|
| 2031 | } |
|
| 2032 | ||
| 2033 | return $this->regexReplace("^[$chars]+", ''); |
|
| 2034 | } |
|
| 2035 | ||
| 2036 | /** |
|
| 2037 | * Returns a string with whitespace removed from the end of the string. |
|
| @@ 2045-2054 (lines=10) @@ | ||
| 2042 | * |
|
| 2043 | * @return Stringy Object with a trimmed $str |
|
| 2044 | */ |
|
| 2045 | public function trimRight($chars = null) |
|
| 2046 | { |
|
| 2047 | if (!$chars) { |
|
| 2048 | $chars = '[:space:]'; |
|
| 2049 | } else { |
|
| 2050 | $chars = preg_quote($chars, '/'); |
|
| 2051 | } |
|
| 2052 | ||
| 2053 | return $this->regexReplace("[$chars]+\$", ''); |
|
| 2054 | } |
|
| 2055 | ||
| 2056 | /** |
|
| 2057 | * Truncates the string to a given length. If $substring is provided, and |
|