It would be a safer to use a snippet like this:
Put this on a page. View it to run the snippet:
[[!SearchReplaceContent? &SearchTerm=`Something` &ReplaceTerm=`Something else`]]
Create a page called TestPage containing the code you want to change. Copy the content to the clipboard so you can restore it the replacement doesn't work correctly.
<?php
/* SearchReplaceContent snippet */
/* try it on one resource first like this */
$resources = $modx->getCollection('modResource', array ('pagetitle' => 'TestPage'));
/* comment out the line above and use this line once it's working:
$resources = $modx->getIterator('modResource', array ('deleted' => '0'));
*/
if (empty($resources)) {
return 'Failed to get any resources';
}
$totalPages = 0;
$totalReplacements = 0;
foreach ($resources as $resource) {
$count = 0;
$content = $resource->getContent();
$content = str_replace($scriptProperties['searchTerm'], $scriptProperties['replaceTerm'], $content, $count);
if ($count) {
$resource->setContent($content);
$resource->save();
$totalReplacements += $count;
$totalPages++;
}
}
return $totalPages . " Resources changed" . " --- " . $totalReplacements . ' Replacements';
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
[ed. note: BobRay last edited this post 11 years, 9 months ago.]