| @@ 374-387 (lines=14) @@ | ||
| 371 | * @param string $subject |
|
| 372 | * @return string |
|
| 373 | */ |
|
| 374 | public static function replaceFirst($search, $replace, $subject) |
|
| 375 | { |
|
| 376 | if ($search == '') { |
|
| 377 | return $subject; |
|
| 378 | } |
|
| 379 | ||
| 380 | $position = strpos($subject, $search); |
|
| 381 | ||
| 382 | if ($position !== false) { |
|
| 383 | return substr_replace($subject, $replace, $position, strlen($search)); |
|
| 384 | } |
|
| 385 | ||
| 386 | return $subject; |
|
| 387 | } |
|
| 388 | ||
| 389 | /** |
|
| 390 | * Replace the last occurrence of a given value in the string. |
|
| @@ 397-406 (lines=10) @@ | ||
| 394 | * @param string $subject |
|
| 395 | * @return string |
|
| 396 | */ |
|
| 397 | public static function replaceLast($search, $replace, $subject) |
|
| 398 | { |
|
| 399 | $position = strrpos($subject, $search); |
|
| 400 | ||
| 401 | if ($position !== false) { |
|
| 402 | return substr_replace($subject, $replace, $position, strlen($search)); |
|
| 403 | } |
|
| 404 | ||
| 405 | return $subject; |
|
| 406 | } |
|
| 407 | ||
| 408 | /** |
|
| 409 | * Begin a string with a single instance of a given value. |
|