Need some one to help me in doing a find and replace task for all the files in my application. I have a list of pairs of old values in one file (findFile.php) and wanted to replace them with different values that are store in second file (replaceFile.php):
findFile.php: -
, "abdomen", "Abdomen";
-
, "afternoon", "Afternoon";
-
, "almost always", "Almost Always";
-
, "almost never", "Almost Never";
-
, "always", "Always";
-
, "bursitis", "Bursitis";
-
, "carpal tunnel syndrome", "Carpal tunnel syndrome";
-
.
-
.
-
.
-
.
to be replaced with the following info stored in replaceFile.php: -
, "10", "Abdomen";
-
, "2", "Afternoon";
-
, "1", "Almost Always";
-
, "4", "Almost Never";
-
, "1", "Always";
-
, "16", "Bursitis";
-
, "21", "Carpal tunnel syndrome";
-
.
-
.
-
.
-
.
I am using this php code and works fine if I do it one by one. But I wanted my script to read from findFile.php, search my entire directory for matching values in the findFile.php and if found, replace them with the corrosponding values in the replaceFile.php. -
<?
-
$findString = 'find string';
-
$replaceString = 'replace with;
-
$path = "/home/nassera/*.*";
-
$findString = "#" . $findString . "#";
-
$globarray = glob($path);
-
$count = 0;
-
if ($globarray) foreach ($globarray as $filename)
-
{
-
$source = file_get_contents($filename);
-
$source = preg_replace($findString,$replaceString,$source);
-
$handle = fopen($filename,"w");
-
fwrite($handle,"$source");
-
fclose($handle);
-
$count++;
-
}
-
?>
1 1488
Heya, Nasse.
Please use CODE tags when posting source code:
[CODE=php]
PHP code goes here.
[/CODE]
Sign in to post your reply or Sign up for a free account.
Similar topics
by: hokieghal99 |
last post by:
import os, string
print " "
setpath = raw_input("Enter the path: ")
def find_replace(setpath):
for root, dirs, files in os.walk(setpath):
fname = files
for fname in files:
find =...
|
by: Bart Nessux |
last post by:
x = str.find(temp, '120.50')
I am looking for '120.50' '120.51' '122.78' etc. How can I do this with
just one str.find... I can use re if I must, but I'd like to avoid it if
possible.
|
by: Xah Lee |
last post by:
suppose you want to do find & replace of string of all files in a
directory.
here's the code:
©# -*- coding: utf-8 -*-
©# Python
©
©import os,sys
©
©mydir= '/Users/t/web'
|
by: Daniel |
last post by:
I use an Access database to basically take data exports, import them,
manipulate the data, and then turn them into exportable reports. I do
this using numerous macros, and queries to get the data...
|
by: James Vitale |
last post by:
Using vb asp.net 1.1
I'm doing a word automation on a doc file and trying to do a find and
replace. My existing code works fine except that it doesn't find and
replace in the header.
My code...
|
by: Xah Lee |
last post by:
Interactive Find and Replace String Patterns on Multiple Files
Xah Lee, 2006-06
Suppose you need to do find and replace of a string pattern, for all
files in a directory. However, you do not...
|
by: Rave |
last post by:
This is a long shot, but I thought I'd try it. I am currently using excel as an inventory tool. I currently have a hand-held scanner plugged into a laptop for reading barcodes. Using the "Find and...
|
by: john |
last post by:
In a table I have text field A. I would like to replace all the null values
in field A to a real value, let's say 'Test'. When I use Find & Replace and
I search for 'is null' and I press replace or...
|
by: TOXiC |
last post by:
Hi everyone,
First I say that I serched and tryed everything but I cannot figure
out how I can do it.
I want to open a a file (not necessary a txt) and find and replace a
string.
I can do it...
|
by: mouac01 |
last post by:
Newbie here. How do I do a find and replace in a binary file? I need
to read in a binary file then replace a string "ABC" with another
string "XYZ" then write to a new file. Find string is the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |