Replace ' / ' character in string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JetJagger
Forum Newbie
Posts: 6
Joined: Sun Jan 20, 2008 11:35 am

Replace ' / ' character in string

Post by JetJagger »

I am running a server-side script that is supposed to replace words in multiple files on my server, but I need the script to replace a string of characters which include the ' / ' (forward slash) character. Unfortunately, the forward slash is causing the script to bark an error code for every instance of the string found! When the forward slash is removed, no problems.

How do I rewrite the following script so that it finds and replaces a string of text that includes the ' / ' (forward slash) character??? Here is the original script:

Code: Select all

require_once('TextSearch.class.php');
 
$path = "/home/hsmhost/public_html/"; //setting path to search
$logFile = "log_result.txt"; //setting log file
 
$obj = new TextSearch();
$obj->setExtensions(array('php')); //setting extensions to search files within
$obj->addExtension('txt');//adding an extension
$obj->setSearchKey('[color=#BF0000]/__HS0108/images/head[/color]'); //what to search for
$obj->setReplacementKey('[color=#BF0000]/images/head[/color]');//setting replacement text if you want to replace matches with that
$obj->startSearching($path);//starting search
$obj->showLog();//showing log
$obj->writeLogToFile($logFile); //writting result to log file
*NOTE: The characters in red are what I need to find and then replace.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: Replace ' / ' character in string

Post by Rovas »

Post Reply