1 | <?php |
||
11 | final class Strings |
||
12 | { |
||
13 | /** |
||
14 | * Replaces the format items in a specified string with the string representation of n specified objects. |
||
15 | * |
||
16 | * @param string $format A composit format string |
||
17 | * @param mixed $arguments Variable number of items to format. |
||
18 | * |
||
19 | * @return string Returns a copy of format in which the format items have been |
||
20 | * replaced by the string representations of arg0, arg1,... argN. |
||
21 | */ |
||
22 | public static function format(string $format, string ...$arguments) : string |
||
30 | |||
31 | /** |
||
32 | * Checks if $string ends with $suffix and puts the rest of the $string in $nonSuffix. |
||
33 | * |
||
34 | * @param string $string The string to check |
||
35 | * @param string $suffix The suffix to check for |
||
36 | * @param mixed &$nonSuffix This is the part of the string that is not the suffix. |
||
37 | * |
||
38 | * @return bool whether the $string ended with $suffix or not. |
||
39 | */ |
||
40 | public static function endsWith(string $string, string $suffix, &$nonSuffix = null) : bool |
||
62 | |||
63 | /** |
||
64 | * Truncates the string to the given length, with an ellipsis at the end. |
||
65 | * |
||
66 | * @param string $string The string to shorten. |
||
67 | * @param int $maxLength The length to truncate the string to. The result will not be longer than this, but may be |
||
68 | * shorter. |
||
69 | * @param string $suffix The string to append when truncating. Typically this will be an ellipsis. |
||
70 | * |
||
71 | * @return string The truncated string with the ellipsis included if truncation occured. |
||
72 | * |
||
73 | * @throws \InvalidArgumentException if $maxLength is negative |
||
74 | */ |
||
75 | public static function ellipsize(string $string, int $maxLength, string $suffix = '...') : string |
||
94 | |||
95 | /** |
||
96 | * Uppercases words using custom word delimiters. |
||
97 | * |
||
98 | * This is more flexible than normal php ucwords because that only treats space as a word delimiter. |
||
99 | * |
||
100 | * Here is an example: |
||
101 | * <code> |
||
102 | * <?php |
||
103 | * $string = 'break-down o\'boy up_town you+me here now,this:place'; |
||
104 | * |
||
105 | * echo String::ucwords($string); |
||
106 | * // Break-Down O\'Boy Up_Town You+Me Here Now,This:Place |
||
107 | * |
||
108 | * echo String::ucwords($string, '- '); |
||
109 | * // Break-Down O\'boy Up_town You+me Here Now,this:place |
||
110 | * ?> |
||
111 | * </code> |
||
112 | * |
||
113 | * @param string $string The string to titleize. |
||
114 | * @param string $delimiters The characters to treat as word delimiters. |
||
115 | * |
||
116 | * @return string The titleized string. |
||
117 | */ |
||
118 | public static function ucwords(string $string, string $delimiters = "-_+' \n\t\r\0\x0B:/,.") : string |
||
132 | } |
||
133 |