@@ 27-40 (lines=14) @@ | ||
24 | * |
|
25 | * @return \Mcustiel\PhpSimpleRegex\ReplaceResult |
|
26 | */ |
|
27 | public function replaceAndCount($pattern, $replacement, $subject, $limit = -1) |
|
28 | { |
|
29 | $count = 0; |
|
30 | $replaced = @preg_replace( |
|
31 | $this->getPatternForReplace($pattern), |
|
32 | $replacement, |
|
33 | $subject, |
|
34 | $limit, |
|
35 | $count |
|
36 | ); |
|
37 | $this->checkResultIsOkForReplaceOrThrowException($replaced, $pattern); |
|
38 | ||
39 | return new ReplaceResult($replaced, $count); |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * Replaces all occurrences of $pattern with $replacement in $subject and returns the result and number |
|
@@ 61-74 (lines=14) @@ | ||
58 | * |
|
59 | * @return \Mcustiel\PhpSimpleRegex\ReplaceResult |
|
60 | */ |
|
61 | public function replaceAndCountAndOnlyGetChanged($pattern, $replacement, $subject, $limit = -1) |
|
62 | { |
|
63 | $count = 0; |
|
64 | // I must display error here, since I couldn't differentiate if error happened or not replace done |
|
65 | $replaced = preg_filter( |
|
66 | $this->getPatternForReplace($pattern), |
|
67 | $replacement, |
|
68 | $subject, |
|
69 | $limit, |
|
70 | $count |
|
71 | ); |
|
72 | ||
73 | return new ReplaceResult($replaced, $count); |
|
74 | } |
|
75 | ||
76 | /** |
|
77 | * Replaces all occurrences of $pattern with $replacement in $subject and returns the replaced subject. |
|
@@ 182-195 (lines=14) @@ | ||
179 | * |
|
180 | * @return \Mcustiel\PhpSimpleRegex\ReplaceResult |
|
181 | */ |
|
182 | public function replaceCallbackAndCount($pattern, callable $callback, $subject, $limit = -1) |
|
183 | { |
|
184 | $count = 0; |
|
185 | $result = preg_replace_callback( |
|
186 | $this->getPatternForReplace($pattern), |
|
187 | $callback, |
|
188 | $subject, |
|
189 | $limit, |
|
190 | $count |
|
191 | ); |
|
192 | $this->checkResultIsOkForReplaceOrThrowException($result, $pattern); |
|
193 | ||
194 | return new ReplaceResult($result, $count); |
|
195 | } |
|
196 | ||
197 | /** |
|
198 | * @param mixed $pattern |