You are here

public function FileOperations::fileStrReplace in AT Tools 8

Same name and namespace in other branches
  1. 8.3 at_theme_generator/src/File/FileOperations.php \Drupal\at_theme_generator\File\FileOperations::fileStrReplace()
  2. 8.2 at_theme_generator/src/File/FileOperations.php \Drupal\at_theme_generator\File\FileOperations::fileStrReplace()

Replace strings in a file.

Parameters

$file_path: The file to be processed (haystack).

$find: The target string (needle).

$replace: The replacement string.

File

at_theme_generator/src/File/FileOperations.php, line 38
Contains \Drupal\at_theme_generator\File\FileOperations

Class

FileOperations

Namespace

Drupal\at_theme_generator\File

Code

public function fileStrReplace($file_path, $find, $replace) {
  if (file_exists($file_path)) {
    $file_contents = file_get_contents($file_path);
    $file_contents = str_replace($find, $replace, $file_contents);
    file_put_contents($file_path, $file_contents);
  }
}