Although PHP can modify files including HTML files, the way dynamic websites work isn't via file editing but rather quite the opposite. The basic goal of a developer using PHP or a Server Side Language is to not modify code based on user input, rather let the code respond to the users request.
Meaning this, lets say I have a PHP file where I display a regular <table>
and the table goes like so
Name | Birthday | Favorite Color
Billy | Dec 2nd | Blue
Darla | March 3rd | Red
Tommy | July 7th | Yellow
The PHP file wouldnt located the HTML file that displays this table and physically change the information in the table. But rather the PHP file that outs the HTML would have the table set up, and pull information from a database and feed it into the table via PHP code. the PHP then output to the end user regular HTML.
So to answer you questions, the actual HTML that you see in your browser's view-source command ISNT what is inside the PHP file. Rather, that's what the PHP file output to the browser.
Therefore, dynamic sites the way they work is they use a language like PHP to query the database and load information. the PHP file then uses that information to generate the HTML. The more experienced you are, the more you can modify the HTML including having pages from the same PHP file that look nothing alike or do the same things.