You shouldn't be needing to make such drastic changes in a template for any website such as modifying element IDs or really even the class names.
For instance, if you need to change the entire layout of the site then you would work on editing your 'main.css' file instead of modifying every individual page. Using CSS you can easily rearrange an entire page's layout, color template and format. Things like this are done all the time in responsive layouts that change a page's design based on the device loading the page, rather than loading an entirely new template.
And even if for some reason you want to make things more complicated you can always go with the first example, using a 'page1.php' file (as well as page2.php, page3.php and so on). This would mean your main template files would never change, only the files added with include().
It's entirely possible to have PHP read a set of files and find certain words, sentences or phrases and then modify the file. However, it would be a terribly inefficient way of handling things.
Think of your page in terms of sections or 'modules'. You have certain modules that are included on the page, for example: your site's name/logo, a navigation bar or menu, page content and a footer. These things would be on your site regardless of which layout/template you use. They are a part of your site's basic design and so those things would not need to change just because you change your layout/template. Instead, those things would be rearranged on the page. They'd be placed in different positions and have different widths/heights as well as different color schemes and styles. So instead of worrying about editing 50 files you should be designing the pages with elements and class names that allow you to control the page's layout via CSS and not basic HTML ordering.
These sorts of things are done all the time with forum and blogging softwares such as phpBB or Wordpress. The pages are made up of individual template files and the page is merely broken up in to sections or modules. When you want to change the layout/template, a new set of files merely rearranges the sections/modules and changes color schemes, images, etc. The page still loads using the same div tags and any other elements and simply alters the CSS styling for these elements to achieve a desired layout.