将两个HTML文件合并为一个主HTML文件

I want to merge two different html files into one,

html1.html

<html>
  <head>
    <link href="blah.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <h1 id="logo">
        <span class="test1">Test text</span>    
    </h1>
  </body>
</html>

html2.html

<html>
  <head>
    <script src="blah.js"></script>
  </head>
  <body>
    <h1 id="logo">
       <span>Test text</span>
       <div class="test2">teststetset</div> 
    </h1>
  </body>
</html>

I want to take these two files and make a master file that would look like this:

<html>
  <head>
    <link href="blah.css" rel="stylesheet" type="text/css" />
    <script src="blah.js"></script>
  </head>
  <body>
    <span class="test1">Test text</span>
    <div class="test2">teststetset</div>
  </body>
</html>

I want to know is this possible using php or any library or using Linux command?