I am trying to replace a section of code within a series of php files. I open the files, read the contents into a "sourcecode" variable and locate a section of code. I then capture this section in a variable like this:


The problem is after I locate this section with the find function, I want to replace the entire section with a string. How do I go about replacing the entire section?


>>> a = 'abcde'
start = 1
end = 2
>>> b = a[:start] + 'z' + a[end:]
>>> b

We've replaced 'b' with 'z'

Is that what you're looking for? You can add

a = b

at the end if you want to keep the variable name.