| @@ 463-476 (lines=14) @@ | ||
| 460 | * @param string $subject |
|
| 461 | * @return string |
|
| 462 | */ |
|
| 463 | public static function replaceFirst($search, $replace, $subject) |
|
| 464 | { |
|
| 465 | if ($search == '') { |
|
| 466 | return $subject; |
|
| 467 | } |
|
| 468 | ||
| 469 | $position = strpos($subject, $search); |
|
| 470 | ||
| 471 | if ($position !== false) { |
|
| 472 | return substr_replace($subject, $replace, $position, strlen($search)); |
|
| 473 | } |
|
| 474 | ||
| 475 | return $subject; |
|
| 476 | } |
|
| 477 | ||
| 478 | /** |
|
| 479 | * Replace the last occurrence of a given value in the string. |
|
| @@ 486-495 (lines=10) @@ | ||
| 483 | * @param string $subject |
|
| 484 | * @return string |
|
| 485 | */ |
|
| 486 | public static function replaceLast($search, $replace, $subject) |
|
| 487 | { |
|
| 488 | $position = strrpos($subject, $search); |
|
| 489 | ||
| 490 | if ($position !== false) { |
|
| 491 | return substr_replace($subject, $replace, $position, strlen($search)); |
|
| 492 | } |
|
| 493 | ||
| 494 | return $subject; |
|
| 495 | } |
|
| 496 | ||
| 497 | /** |
|
| 498 | * Begin a string with a single instance of a given value. |
|