Created
April 3, 2012 14:32
-
-
Save ecorson/2292454 to your computer and use it in GitHub Desktop.
Search and replace text using Views Bulk Operations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Search and replace using Views Bulk Operations | |
*/ | |
$node = node_load($entity->nid); //load node form entity supplied by VBO | |
$haystack = $node->body['und'][0]['value']; //set node body to be haystack | |
$search = "Office of International Students and Scholars"; //Set the string to search for | |
$replace = "International Student & Scholar Services"; //String to replace target | |
$pos = strpos($string, $search); | |
//test if the string exists before attempting to replace | |
if ($pos != false) { | |
drupal_set_message(l($node->title, 'node/'.$entity->nid)); //link to node with change | |
$node->body['und'][0]['value'] = str_replace($search, $replace, $haystack); | |
node_save($node); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment