Search and Replace

NEWS & TIPS

  • Site Access Keys
  • Top: Alt+t
    Previous: Alt+,
    Next: Alt+.
    Up: Alt+;
    (Note: use Ctrl on the Mac)

Search and Replace

Author: Martin Robinson

1. Introduction

This guide will quickly walk you through installing and configuring a the search and replace script. This script will read the name of a Cascade directory, search term and replacement term from a config file. Finding the search term among text on the pages in that directory, the script will replace it with the replacement term.

2. The Script

Create a file in your search directory, turn off indexing on the file and change the content to that of the search-replace.php file included above. This is the script which will do the search and replace. Notice that at the top of this file is the line $config_file = "search-replace-config.xml". We will create this configuration file next.

3. The Configuration Editor

Instead of simply uploading a configuration file, we will create a data definition, so that we can edit the configuration file inside of the CMS.  Create a data definition (we called ours "Search and Replace Config") using the included data definition search-replace-config.xml.

Now create a page named config with the data definition that you just created. If possible configure the page so that it publishes XML to .xml file. If not, you will have to change the $config_file variable in search-replace.php to reflect the file extension that this page publishes to. In any case, it must output XML.

This configuration must be filtered as well, so load the stylesheet "search-replace-config.xsl" and assign it to the page you just created. If you edit the page you just created you will be presented with some configuration options. Most are self explanatory.

4. Finishing Up

Now once, you publish your assets, you should be able to run the PHP script that you just published. It may take a while to do a search and replace on a large directory, so be patient. The best solution is to run the PHP file from the command-line for interactive output.

Example Files 

  1. search-and-replace-PHP.zip
    This is a zip file with all the necessary scripts and XML.
  2. search-replace-config-data-definition.xml
    This is a data definition to visually configure the XML config file.
  3. search-replace-config.xsl
    This is the example XSL to transform the XML from the data definition into the XML for the config file.
  4. search-replace-config.xml
    This is the example XML config file.
  5. search-replace-php.txt
    This is the main PHP script that processes the search and replace.
Last modified on Fri, 28 Jul 2006 15:16:47 -0400

Top / Up / Table of Contents