You're still being a bit vague.
OK, so you have a bunch of PHP files with a lot of lines
like the above and you want to replace those four lines of code with four other lines of code.
But how alike are the other blocks of code?
Are they all
exactly the same as your example?
Or are some of them
slightly different?
How alike are they?
If any are slightly different it's going to complicate things rather a lot because you'd need to set up separate regex patterns to correctly identify
ALL of the blocks of code you're interested in and specify the lines of code that will replace each pattern.... Doing that would require manually going through the code and finding all sections and then writing a regex for each unique block, writing a replacement pattern. etc. etc.
If you have to go that far, it will probably be quicker to just edit the files directly.
Another option might be to write a script that could parse the PHP files and identify four line sections of code that meet your criteria and then replace them with whatever you deem is necessary, but again - that will probably take more time to set up than simply editing the files yourself.
Another thing to take into consideration is:
If
all of the sections of code you are interested in replacing are
exactly the same - wouldn't it be better to put the four replacement lines of code into a function and then call the function at each place where the code has been duplicated?
There's no point replacing duplicate code with even more duplicate code.
Is there any particular reason you feel you HAVE to use sed? This task might be something more suited to macros in a text editor like vim or emacs, or some other tool.