ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
◀ ilDoc Overview
Replace.php
Go to the documentation of this file.
1
<?
php
2
3
namespace
PhpOffice\PhpSpreadsheet\Calculation\TextData
;
4
5
use
PhpOffice\PhpSpreadsheet\Calculation\Functions
;
6
7
class
Replace
8
{
17
public
static
function
replace
($oldText,
$start
, $chars, $newText): string
18
{
19
$oldText =
Functions::flattenSingleValue
($oldText);
20
$start
=
Functions::flattenSingleValue
(
$start
);
21
$chars =
Functions::flattenSingleValue
($chars);
22
$newText =
Functions::flattenSingleValue
($newText);
23
24
$left =
Extract::left
($oldText,
$start
- 1);
25
$right =
Extract::right
($oldText,
Text::length
($oldText) - (
$start
+ $chars) + 1);
26
27
return
$left . $newText . $right;
28
}
29
38
public
static
function
substitute
(
$text
=
''
, $fromText =
''
, $toText =
''
,
$instance
= 0): string
39
{
40
$text
=
Functions::flattenSingleValue
(
$text
);
41
$fromText =
Functions::flattenSingleValue
($fromText);
42
$toText =
Functions::flattenSingleValue
($toText);
43
$instance
= floor(
Functions::flattenSingleValue
(
$instance
));
44
45
if
(
$instance
== 0) {
46
return
str_replace($fromText, $toText,
$text
);
47
}
48
49
$pos = -1;
50
while
(
$instance
> 0) {
51
$pos = mb_strpos(
$text
, $fromText, $pos + 1,
'UTF-8'
);
52
if
($pos ===
false
) {
53
break
;
54
}
55
--
$instance
;
56
}
57
58
if
($pos !==
false
) {
59
return
self::REPLACE(
$text
, ++$pos, mb_strlen($fromText,
'UTF-8'
), $toText);
60
}
61
62
return
$text
;
63
}
64
}
PhpOffice\PhpSpreadsheet\Calculation\TextData
Definition:
CaseConvert.php:3
PhpOffice\PhpSpreadsheet\Calculation\TextData\Extract\left
static left($value='', $chars=1)
LEFT.
Definition:
Extract.php:16
$start
$start
Definition:
bench.php:8
PhpOffice\PhpSpreadsheet\Calculation\TextData\Extract\right
static right($value='', $chars=1)
RIGHT.
Definition:
Extract.php:62
$text
$text
Definition:
errorreport.php:18
PhpOffice\PhpSpreadsheet\Calculation\Calculation\$instance
static $instance
Definition:
Calculation.php:60
PhpOffice\PhpSpreadsheet\Calculation\TextData\Replace\substitute
static substitute($text='', $fromText='', $toText='', $instance=0)
SUBSTITUTE.
Definition:
Replace.php:38
PhpOffice\PhpSpreadsheet\Calculation\TextData\Text\length
static length($value='')
STRINGLENGTH.
Definition:
Text.php:15
Functions
PhpOffice\PhpSpreadsheet\Calculation\TextData\Replace\replace
static replace($oldText, $start, $chars, $newText)
REPLACE.
Definition:
Replace.php:17
PhpOffice\PhpSpreadsheet\Calculation\TextData\Replace
Definition:
Replace.php:7
php
PhpOffice\PhpSpreadsheet\Calculation\Functions\flattenSingleValue
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition:
Functions.php:649
libs
composer
vendor
phpoffice
phpspreadsheet
src
PhpSpreadsheet
Calculation
TextData
Replace.php
Generated on Thu Jan 30 2025 19:01:23 for ILIAS by
1.8.13 (using
Doxyfile
)