[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Search and replace question



I've been editing some old php code, and wanted to tidy it up a bit before 
making more changes.

There are a lot of lines like the following:

echo '<input type="submit" name="block-" . $blocckno . ">';

Because of the way quotes work in php, if the line is enclosed in single 
quotes, variable names aren't expended, hence the need to use dots to 
concatenate things.

I'd line to convert the line into:

echo "<input type='submit' name='block-' . $blocckno . '>";

in an S&R operation, so that I can get rid of the dotted bits manually 
later, and add \n inside the final double quote.

The problem is that I need to replace single quotes with double, and 
double quotes with single. Any obvious solution is likely to replace a 
single with a double, then replace the double with a single, restoring the 
original.

I can do it with three successive operations - replace double quote with 
@@@, then replace single with double, then replace @@@ with single, but 
it's cumbersome.

Is there a better way?

Also, can it be limited to lines where the first quote is a single one?

-- 
Alan Adams, from Northamptonshire
alan@xxxxxxxxxxxxxxxx
http://www.nckc.org.uk/