Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Perform a regular expression search and replace
<?php preg_replace( string|array $pattern, string|array $replacement, string|array $subject, int $limit = -1, int &$count = null): string|array|null
<?php $cwd = rtrim($cwd, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
return preg_replace('/^' . preg_quote($cwd, '/') . '/', '', $file);
}
}
<?php }
if ($inline) {
$template = preg_replace('/\[quote\]/', $this->wisdomOfTheTao(), $template);
}
return preg_replace(
<?php $template = preg_replace('/\[quote\]/', $this->wisdomOfTheTao(), $template);
}
return preg_replace(
['/\[namespace\]/', '/\[class\]/', '/\[view\]/'],
[$this->classNamespace(), $this->className(), $this->viewName()],
$template
);
}
public function viewPath()
<?php $stubPath = __DIR__.DIRECTORY_SEPARATOR.'livewire.view.stub';
}
return preg_replace(
'/\[quote\]/',
$this->wisdomOfTheTao(),
file_get_contents($stubPath)
);
}
public function testNamespace()
<?php $template = file_get_contents(__DIR__.DIRECTORY_SEPARATOR.$stubName);
}
return preg_replace(
['/\[testnamespace\]/', '/\[classwithnamespace\]/', '/\[testclass\]/', '/\[class\]/'],
[$this->testNamespace(), $this->classNamespace() . '\\' . $this->className(), $this->testClassName(), $this->className()],
$template
);
}
public function wisdomOfTheTao()
<?php {
$originalFile = file_get_contents($this->existingParser->classPath());
$escapedClassNamespace = preg_replace('/\\\/', '\\\\\\', $this->existingParser->classNamespace());
return preg_replace_array(
["/namespace {$escapedClassNamespace}/", "/class {$this->existingParser->className()}/", "/{$this->existingParser->viewName()}/"],
<?php {
$file_content = file_get_contents($this->existingParser->testPath());
$escapedTestNamespace = preg_replace('/\\\/', '\\\\\\', $this->existingParser->testNamespace());
$escapedClassWithNamespace = preg_replace('/\\\/', '\\\\\\', $this->existingParser->classNamespace() . '\\' . $this->existingParser->className());
$replaces = [
<?php $file_content = file_get_contents($this->existingParser->testPath());
$escapedTestNamespace = preg_replace('/\\\/', '\\\\\\', $this->existingParser->testNamespace());
$escapedClassWithNamespace = preg_replace('/\\\/', '\\\\\\', $this->existingParser->classNamespace() . '\\' . $this->existingParser->className());
$replaces = [
"/namespace {$escapedTestNamespace}/" => "namespace " . $this->testNamespace(),
<?php "/{$this->existingParser->className()}::class/" => $this->className() . '::class',
];
return preg_replace(array_keys($replaces), array_values($replaces), $file_content);
}
}
<?php if($replacement instanceof Closure) {
$file['content'] = preg_replace_callback($pattern, $replacement, $file['content'], -1, $count);
} else {
$file['content'] = preg_replace($pattern, $replacement, $file['content'], -1, $count);
}
$file['occurrences'] = $count;
<?php $pattern = "/(?<!{$prefixEscaped}){$foundEscaped}(?![^<]*(?<![?=-])>)/mUi";
return preg_replace($pattern, $foundWithPrefix, $template);
}
protected static function suffixClosingDirective($found, $template)
<?php $pattern = "/{$foundEscaped}(?!\w)(?!{$suffixEscaped})(?![^<]*(?<![?=-])>)/mUi";
return preg_replace($pattern, $foundWithSuffix, $template);
}
protected static function directivesPattern($directives)
<?php protected static function minify($subject)
{
return preg_replace('~(\v|\t|\s{2,})~m', '', $subject);
}
}
<?php protected function extractChannelKeys($pattern, $channel)
{
preg_match('/^'.preg_replace('/\{(.*?)\}/', '(?<$1>[^\.]+)', $pattern).'/', $channel, $keys);
return $keys;
}
<?php protected function channelNameMatchesPattern($channel, $pattern)
{
return preg_match('/^'.preg_replace('/\{(.*?)\}/', '([^\.]+)', $pattern).'$/', $channel);
}