Including file in head using PHP string replace

I am trying to include a head.php file in index.php using PHP string replace.

My Code (index.php) :

$headin = include "head.php";

$context = stream_context_create(
    array(
        "http" => array(
            "header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
        )
    )
);

$homepage = file_get_contents("https://www.example.com/", false, $context);
$homepage = str_replace("<head>", "<head>". $headin, $homepage);
echo $homepage;

The problem is, the content of head.php displaying above the <html> instead of displaying inside <head>. Please help to get it fixed.