method replaceContents documentation in bbn\File\System
Replaces search with replace in the given content.
function($search, $replace, $path, $deep = false, $hidden = false, $filter = 'file')
{
if (\is_array($replace)) {
if (!\is_array($search) || (count($replace) !== count($search))) {
throw new \Exception(X::_("If replace is an array, search must be an array of equal length"));
}
$replace_array = true;
}
$res = 0;
if ($this->isDir($path)) {
$files = $deep ? $this->scan($path, $filter) : $this->getFiles($path, false, $hidden, $filter);
foreach ($files as $f) {
$res += $this->replaceContents($search, $replace, $f);
}
return $res;
} elseif ($this->isFile($path)) {
$content = $this->getContents($path);
$changed = false;
if (is_array($search)) {
foreach ($search as $idx => $s) {
if (X::indexOf($content, $s) === -1) {
continue;
}
$changed = true;
$content = str_replace($s, $replace_array ? $replace[$idx] : $replace, $content);
}
} elseif (X::indexOf($content, $search) > -1) {
$changed = true;
$content = str_replace($search, $replace, $content);
}
if ($changed) {
$this->putContents($path, $content);
return 1;
}
return $res;
}
return 0;
}
Replaces search with replace in the given content. 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.
© 2011-2025
BBN Solutions