phputils is a share utility library
use K92\Phputils\StrUtil;
// normal case
str_replace([1, 2], [2, 3], '12'); // '33'
StrUtil::replaceOnce([1, 2], [2, 3], '12'); // '23'
str_replace(['1', '0'], ['x110x2', 'x010'], 'a1b0c') // 'ax11x010x2bx010c'
StrUtil::replaceOnce(['1', '0'], ['x110x2', 'x010'], 'a1b0c') // 'ax110x2bx010c'
// edge case
str_replace([12, 23], [23, 45], '123') // '453'
StrUtil::replaceOnce([12, 23], [23, 45], '123') // false
str_replace([12, 23], [23, 45], '1223') // '4545'
StrUtil::replaceOnce([12, 23], [23, 45], '1223') // false
Need mbstring extension
Use the package manager composer to install phputils.
composer require k92/phputils
./vendor/bin/phpunit tests
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.