method replaceOnce documentation in bbn\Str

Replaces part of a string. If the part is not found, the method returns the string without change.

Example

X::hdump(\bbn\Str::replaceOnce("cold","hot", "Today there is cold")); // (string) "Today there is hot" X::hdump(\bbn\Str::replaceOnce("rain","hot", "Today there is cold")); // (string) "Today there is cold" function($search, $replace, $subject) { $pos = strpos($subject, $search); if ($pos !== false) { return substr_replace($subject, $replace, $pos, \strlen($search)); } return $subject; }

Replaces part of a string. If the part is not found, the method returns the string without change. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.