1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace PhpOffice\PhpSpreadsheet\Calculation\TextData;
|
|
|
4 |
|
|
|
5 |
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
|
|
6 |
|
|
|
7 |
class Trim
|
|
|
8 |
{
|
|
|
9 |
use ArrayEnabled;
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* CLEAN.
|
|
|
13 |
*
|
|
|
14 |
* @param mixed $stringValue String Value to check
|
|
|
15 |
* Or can be an array of values
|
|
|
16 |
*
|
|
|
17 |
* @return array|string If an array of values is passed as the argument, then the returned result will also be an array
|
|
|
18 |
* with the same dimensions
|
|
|
19 |
*/
|
|
|
20 |
public static function nonPrintable(mixed $stringValue = '')
|
|
|
21 |
{
|
|
|
22 |
if (is_array($stringValue)) {
|
|
|
23 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $stringValue);
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
$stringValue = Helpers::extractString($stringValue);
|
|
|
27 |
|
|
|
28 |
return (string) preg_replace('/[\x00-\x1f]/', '', "$stringValue");
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* TRIM.
|
|
|
33 |
*
|
|
|
34 |
* @param mixed $stringValue String Value to check
|
|
|
35 |
* Or can be an array of values
|
|
|
36 |
*
|
|
|
37 |
* @return array|string If an array of values is passed as the argument, then the returned result will also be an array
|
|
|
38 |
* with the same dimensions
|
|
|
39 |
*/
|
|
|
40 |
public static function spaces(mixed $stringValue = ''): array|string
|
|
|
41 |
{
|
|
|
42 |
if (is_array($stringValue)) {
|
|
|
43 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $stringValue);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
$stringValue = Helpers::extractString($stringValue);
|
|
|
47 |
|
|
|
48 |
return trim(preg_replace('/ +/', ' ', trim("$stringValue", ' ')) ?? '', ' ');
|
|
|
49 |
}
|
|
|
50 |
}
|