| @@ 215-224 (lines=10) @@ | ||
| 212 | * |
|
| 213 | * @return Stringy Object with a trimmed $str |
|
| 214 | */ |
|
| 215 | public function trim($chars = null) |
|
| 216 | { |
|
| 217 | if (!$chars) { |
|
| 218 | $chars = '[:space:]'; |
|
| 219 | } else { |
|
| 220 | $chars = preg_quote($chars, '/'); |
|
| 221 | } |
|
| 222 | ||
| 223 | return $this->regexReplace("^[$chars]+|[$chars]+\$", ''); |
|
| 224 | } |
|
| 225 | ||
| 226 | /** |
|
| 227 | * Replaces all occurrences of $pattern in $str by $replacement. |
|
| @@ 1704-1713 (lines=10) @@ | ||
| 1701 | * |
|
| 1702 | * @return Stringy Object with a trimmed $str |
|
| 1703 | */ |
|
| 1704 | public function trimLeft($chars = null) |
|
| 1705 | { |
|
| 1706 | if (!$chars) { |
|
| 1707 | $chars = '[:space:]'; |
|
| 1708 | } else { |
|
| 1709 | $chars = preg_quote($chars, '/'); |
|
| 1710 | } |
|
| 1711 | ||
| 1712 | return $this->regexReplace("^[$chars]+", ''); |
|
| 1713 | } |
|
| 1714 | ||
| 1715 | /** |
|
| 1716 | * Returns a string with whitespace removed from the end of the string. |
|
| @@ 1724-1733 (lines=10) @@ | ||
| 1721 | * |
|
| 1722 | * @return Stringy Object with a trimmed $str |
|
| 1723 | */ |
|
| 1724 | public function trimRight($chars = null) |
|
| 1725 | { |
|
| 1726 | if (!$chars) { |
|
| 1727 | $chars = '[:space:]'; |
|
| 1728 | } else { |
|
| 1729 | $chars = preg_quote($chars, '/'); |
|
| 1730 | } |
|
| 1731 | ||
| 1732 | return $this->regexReplace("[$chars]+\$", ''); |
|
| 1733 | } |
|
| 1734 | ||
| 1735 | /** |
|
| 1736 | * Truncates the string to a given length. If $substring is provided, and |
|