You are here

function _vbo_search_and_replace_search_and_replace in Views Bulk Operations Search & Replace 7

Same name and namespace in other branches
  1. 6 vbo_search_and_replace.module \_vbo_search_and_replace_search_and_replace()

Performs a search and replace on a value and returns the result.

Search is case insensitive by default but can be changed in $settings.

Parameters

string $search: The value to search for.

string $replace: The value to use as a replacement.

string $subject: The Value to perform search and replace on.

array $settings: An array of settings for the search and replace:

  • regular_expression: Set to TRUE for a regular expression search.
  • search_prefix: Add a prefix to the search.
  • search_suffix: Add a suffix to the search.
  • exact_match: Set to TRUE to match entire $subject instead of just a part.
  • case_sensitive: Set to TRUE to make the search case sensitive.
1 call to _vbo_search_and_replace_search_and_replace()
vbo_search_and_replace_action in ./vbo_search_and_replace.module
Action function.

File

includes/vbo_search_and_replace.inc, line 93
Private helper functions for VBO Search and Replace.

Code

function _vbo_search_and_replace_search_and_replace($search, $replace, $subject, array $settings = array()) {
  if ($settings['regular_expression']) {
    try {
      $subject = preg_replace($search, $replace, $subject);
    } catch (Exception $e) {
      drupal_set_message('There was an error performing a search and replace with this regular expression.', 'error');
    }
  }
  else {
    $search = $settings['search_prefix'] . $search . $settings['search_suffix'];
    $replace = $settings['search_prefix'] . $replace . $settings['search_suffix'];
    if ($settings['exact_match'] && $subject === $search) {
      $subject = $replace;
    }
    elseif ($settings['case_sensitive']) {
      $subject = str_replace($search, $replace, $subject);
    }
    else {
      $subject = str_ireplace($search, $replace, $subject);
    }
  }
  return $subject;
}