mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 04:23:01 +00:00
Add str_replace_once to core
This commit is contained in:
parent
fa1f03f38a
commit
94378d8c31
1 changed files with 14 additions and 0 deletions
14
core.php
14
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
|
||||
|
|
Loading…
Reference in a new issue