I know I can include other files using PHP
Now my question is how do I inject only certain parts of \
The easiest (and usual) way is to simply make separate header.php and footer.php files, and access them where you need them. There's no direct support for only loading parts of a file.
Edit (to respond to your comment on the other answer about using separate functions): Let's say your file.php looks like this:
header content goes here
footer content goes here
Then in the page you're calling it into, you can use and
to produce the content where you want it.