function _vbo_search_and_replace_search_and_replace in Views Bulk Operations Search & Replace 6
Same name and namespace in other branches
- 7 includes/vbo_search_and_replace.inc \_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
$search: The value to search for
$replace: The value to use as a replacement
$value: The Value to perform search and replace on
$settings: An array of settings for the search and replace:
- 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()
File
Code
function _vbo_search_and_replace_search_and_replace($search, $replace, $subject, $settings = array()) {
// Set up settings that aren't set
$settings['search_prefix'] = isset($settings['search_prefix']) ? $settings['search_prefix'] : '';
$settings['search_suffix'] = isset($settings['search_suffix']) ? $settings['search_suffix'] : '';
$settings['case_sensitive'] = isset($settings['case_sensitive']) ? $settings['case_sensitive'] : '';
$settings['exact_match'] = isset($settings['exact_match']) ? $settings['exact_match'] : '';
// Our search and replace strings WITH prefix and suffix
$search = $settings['search_prefix'] . $search . $settings['search_suffix'];
$replace = $settings['search_prefix'] . $replace . $settings['search_suffix'];
// If it's an exact match, perform search and replace on the entire value
if ($settings['exact_match']) {
if ($subject === $search) {
$subject = $replace;
}
}
else {
if ($settings['case_sensitive']) {
if (strpos($subject, $search) !== FALSE) {
$subject = str_replace($search, $replace, $subject);
}
}
else {
if (strpos(strtolower($subject), strtolower($search)) !== FALSE) {
$subject = str_ireplace($search, $replace, $subject);
}
}
}
// Return the subject
return $subject;
}