in reply to general advice finding duplicate code
In the case of classic PHP, it might be a valid approach to consider the problem as being one of “extracting the (small) amounts of code” from what is basically “a very large and ugly template.” PHP strongly encouraged the mix-up of code and (in effect) data in the same file, and, “as soon as it works, sort of, go on to the next one starting with a copy of the last one.” Perhaps, though, a preponderance of the actual material is HTML, rather than logic?