1 | <?php |
||
28 | class StringUtil |
||
|
|||
29 | { |
||
30 | |||
31 | /** |
||
32 | * The MIT License (MIT) |
||
33 | * |
||
34 | * Copyright (c) <Taylor Otwell> |
||
35 | * |
||
36 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
37 | * of this software and associated documentation files (the "Software"), to deal |
||
38 | * in the Software without restriction, including without limitation the rights |
||
39 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
40 | * copies of the Software, and to permit persons to whom the Software is |
||
41 | * furnished to do so, subject to the following conditions: |
||
42 | * |
||
43 | * The above copyright notice and this permission notice shall be included in |
||
44 | * all copies or substantial portions of the Software. |
||
45 | * |
||
46 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
47 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
48 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
49 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
50 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
51 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
52 | * THE SOFTWARE |
||
53 | * |
||
54 | * Generate a more truly "random" alpha-numeric string. |
||
55 | * |
||
56 | * @param int $length |
||
57 | * @return string |
||
58 | * |
||
59 | * @throws \RuntimeException |
||
60 | */ |
||
61 | public static function random($length = 16) |
||
75 | |||
76 | /** |
||
77 | * The MIT License (MIT) |
||
78 | * |
||
79 | * Copyright (c) <Taylor Otwell> |
||
80 | * |
||
81 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
82 | * of this software and associated documentation files (the "Software"), to deal |
||
83 | * in the Software without restriction, including without limitation the rights |
||
84 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
85 | * copies of the Software, and to permit persons to whom the Software is |
||
86 | * furnished to do so, subject to the following conditions: |
||
87 | * |
||
88 | * The above copyright notice and this permission notice shall be included in |
||
89 | * all copies or substantial portions of the Software. |
||
90 | * |
||
91 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
92 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
93 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
94 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
95 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
96 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
97 | * THE SOFTWARE |
||
98 | * |
||
99 | * Generate a "random" alpha-numeric string. |
||
100 | * |
||
101 | * Should not be considered sufficient for cryptography, etc. |
||
102 | * |
||
103 | * @param int $length |
||
104 | * @return string |
||
105 | */ |
||
106 | public static function quickRandom($length = 16) |
||
112 | |||
113 | |||
114 | /** |
||
115 | * 改行コードの変換 |
||
116 | * |
||
117 | * @param $value |
||
118 | * @param string $lf |
||
119 | * @return string |
||
120 | */ |
||
121 | public static function convertLineFeed($value, $lf = "\n") |
||
128 | |||
129 | /** |
||
130 | * 文字コードの判定 |
||
131 | * |
||
132 | * @param $value |
||
133 | * @return string |
||
134 | */ |
||
135 | public static function characterEncoding($value, $encoding = array('UTF-8', 'SJIS', 'EUC-JP', 'ASCII', 'JIS', 'sjis-win')) |
||
146 | |||
147 | /** |
||
148 | * 指定した文字列以上ある場合、「...」を付加する |
||
149 | * lengthに7を指定すると、「1234567890」は「1234567...」と「...」を付与して出力される |
||
150 | * |
||
151 | * @param string $value |
||
152 | * @param int $length |
||
153 | * @param string $end |
||
154 | * @return string |
||
155 | */ |
||
156 | public static function ellipsis($value, $length = 100, $end = '...') |
||
164 | |||
165 | |||
166 | /** |
||
167 | * 現在からの経過時間を書式化する. |
||
168 | * |
||
169 | * @param $date |
||
170 | * @return string |
||
171 | */ |
||
172 | public static function timeAgo($date) |
||
202 | |||
203 | /** |
||
204 | * 変数が空白かどうかをチェックする. |
||
205 | * |
||
206 | * 引数 $value が空白かどうかをチェックする. 空白の場合は true. |
||
207 | * 以下の文字は空白と判断する. |
||
208 | * - ' ' (ASCII 32 (0x20)), 通常の空白 |
||
209 | * - "\t" (ASCII 9 (0x09)), タブ |
||
210 | * - "\n" (ASCII 10 (0x0A)), リターン |
||
211 | * - "\r" (ASCII 13 (0x0D)), 改行 |
||
212 | * - "\0" (ASCII 0 (0x00)), NULバイト |
||
213 | * - "\x0B" (ASCII 11 (0x0B)), 垂直タブ |
||
214 | * |
||
215 | * 引数 $value がオブジェクト型、配列の場合は非推奨とし、 E_USER_DEPRECATED をスローする. |
||
216 | * EC-CUBE2系からの互換性、ビギナー層を配慮し、以下のような実装とする. |
||
217 | * 引数 $value が配列の場合は, 空の配列の場合 true を返す. |
||
218 | * 引数 $value が ArrayCollection::isEmpty() == true の場合 true を返す. |
||
219 | * 引数 $value が上記以外のオブジェクト型の場合は false を返す. |
||
220 | * |
||
221 | * 引数 $greedy が true の場合は, 全角スペース, ネストした空の配列も |
||
222 | * 空白と判断する. |
||
223 | * |
||
224 | * @param string $value チェック対象の変数. 文字型以外も使用できるが、非推奨. |
||
225 | * @param boolean $greedy '貧欲'にチェックを行う場合 true, デフォルト false |
||
226 | * @return boolean $value が空白と判断された場合 true |
||
227 | */ |
||
228 | public static function isBlank($value, $greedy = false) |
||
285 | |||
286 | /** |
||
287 | * @param $value |
||
288 | * @return bool |
||
289 | */ |
||
290 | public static function isNotBlank($value, $greedy = false) |
||
294 | |||
295 | /** |
||
296 | * 両端にある全角スペース、半角スペースを取り除く |
||
297 | * |
||
298 | * @param $value |
||
299 | * @return string |
||
300 | */ |
||
301 | public static function trimAll($value) |
||
314 | } |
||
315 |