1 | <?php |
||
11 | class StringHelper |
||
12 | { |
||
13 | /** @var bool Whether the mbstring extension is loaded */ |
||
14 | protected $hasMbstringSupport; |
||
15 | |||
16 | /** @var bool Whether the code is running with PHP7 or older versions */ |
||
17 | private $isRunningPhp7OrOlder; |
||
18 | |||
19 | /** @var array Locale info, used for number formatting */ |
||
20 | private $localeInfo; |
||
21 | |||
22 | /** |
||
23 | * |
||
24 | */ |
||
25 | public function __construct() |
||
31 | |||
32 | /** |
||
33 | * Returns the length of the given string. |
||
34 | * It uses the multi-bytes function is available. |
||
35 | * @see strlen |
||
36 | * @see mb_strlen |
||
37 | * |
||
38 | * @param string $string |
||
39 | * @return int |
||
40 | */ |
||
41 | public function getStringLength($string) |
||
45 | |||
46 | /** |
||
47 | * Returns the position of the first occurrence of the given character/substring within the given string. |
||
48 | * It uses the multi-bytes function is available. |
||
49 | * @see strpos |
||
50 | * @see mb_strpos |
||
51 | * |
||
52 | * @param string $char Needle |
||
53 | * @param string $string Haystack |
||
54 | * @return int Char/substring's first occurrence position within the string if found (starts at 0) or -1 if not found |
||
55 | */ |
||
56 | public function getCharFirstOccurrencePosition($char, $string) |
||
62 | |||
63 | /** |
||
64 | * Returns the position of the last occurrence of the given character/substring within the given string. |
||
65 | * It uses the multi-bytes function is available. |
||
66 | * @see strrpos |
||
67 | * @see mb_strrpos |
||
68 | * |
||
69 | * @param string $char Needle |
||
70 | * @param string $string Haystack |
||
71 | * @return int Char/substring's last occurrence position within the string if found (starts at 0) or -1 if not found |
||
72 | */ |
||
73 | public function getCharLastOccurrencePosition($char, $string) |
||
79 | |||
80 | /** |
||
81 | * Formats a numeric value (int or float) in a way that's compatible with the expected spreadsheet format. |
||
82 | * |
||
83 | * Formatting of float values is locale dependent in PHP < 8. |
||
84 | * Thousands separators and decimal points vary from locale to locale (en_US: 12.34 vs pl_PL: 12,34). |
||
85 | * However, float values must be formatted with no thousands separator and a "." as decimal point |
||
86 | * to work properly. This method can be used to convert the value to the correct format before storing it. |
||
87 | * |
||
88 | * @see https://wiki.php.net/rfc/locale_independent_float_to_string for the changed behavior in PHP8. |
||
89 | * |
||
90 | * @param int|float $numericValue |
||
91 | * @return string |
||
92 | */ |
||
93 | public function formatNumericValue($numericValue) |
||
105 | } |
||
106 |