From 94378d8c31d900b05ddb859e927a91cba8b8afd3 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 20 May 2017 15:58:55 +0100 Subject: [PATCH] Add str_replace_once to core --- core.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core.php b/core.php index 58aa336..1a5a33f 100644 --- a/core.php +++ b/core.php @@ -384,6 +384,20 @@ function endsWith($whole, $end) { return (strpos($whole, $end, strlen($whole) - strlen($end)) !== false); } +/** + * Replaces the first occurrence of $find with $replace. + * @param string $find The string to search for. + * @param string $replace The string to replace the search string with. + * @param string $subject The string ot perform the search and replace on. + * @return string The source string after the find and replace has been performed. + */ +function str_replace_once($find, $replace, $subject) +{ + $index = strpos($subject, $find); + if($index !== false) + return substr_replace($subject, $replace, $index, strlen($find)); + return $subject; +} /** * Returns the system's mime type mappings, considering the first extension