Preg_replace in CSV file

Hi Guys!

I have a CSV file in which I need to replace some text. In column 1 I have the old phrase (of which I need to replace part of it with column 3). Column 2 is not required.

So for example here is row 1 (I have also added column 1,2,3 above each column)


Column 1
$language['admin_index_page_title'] = "Welcome to Admin";

Column 2	
Welcome to Admin.	

Column 3
Админд тавтай морилно уу.

Now what I need to do is replace the text within double quotes from column 1 with the text in column 3. So column 1 will end up like this:


$language['admin_index_page_title'] = "Админд тавтай морилно уу.";

Any ideas how to do this?

Thanks.

preg_replace(‘~(.?").?";,(.?),(.?)
~’,'$1$3";,$2,$3
',$csvfilecontents);

(COMPLETELY untested. Test before writing back to the file. I’m assuming your fields are not quote-encapsulated, are seperated by commas, and lines are delimited by newline)

Why not just reassign the column in the row?


<?php
$row[0] = $row[2];

It’s not replacing the value entirely, Anthony, he wants to slice it into the space between the quotes… essentially the CSV file is a massive Find/Replace (Needle = Row[1], Replace = Row[2], Haystack = Row[0])

Ah, got you. Thanks StarLion.