如何创建一个主要的PHP文件,以便其他php文件可以填补空白?

I am busy with practising how to create a website. Now I would like to do it in a way that feels right for me. But at the moment I am failing to create a main page where I am later able to fill in the blanks. With the title it was easy and I succeeded in setting the title on different pages. But when I try to set the content of the complete page, I fail.

This would be my page for filling in the blanks:

<!doctype html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <title><?php echo $title ?></title>
    <?php require 'navigation.php'; ?>
</head>
<body>
    <div class="content">
        <?php $content ?>
    </div>
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
</body>
<?php require 'footer.php'; ?>
</html>

The code below will be my index page. If I would set my $content as I did below it works, but I am not content with this solution cause the part behind the equals-sign will be seen as a string and it does not feel neat.

<?php $title = "Home";?>
<?php $content = "<div class='container bg-image'></div>" ?>


<?php require '..esources\views\main.php';?>

So my question is can I do this in a better way? And how would I do that?

At this stage in learning how to write PHP, i would suggest including files based on your whereabouts on the page.

But before doing so, i would like to point out that you are not echoing the content in your code. You wrote <?php $content; ?> but should instead write <?php echo $content; ?> for the current approach.

Now, back to my suggestion:
Let's have this file structure:

/content/home.php
/content/about.php
/includes/navigation.php
/index.php

Each file in the content folder can for practise just contain raw HTML which you want to display where you for now have <?php echo $content; ?>

Alright, let's open index.php

<?php
// Content of index.php
$defaultpage = 'home';

// We would like to display different pages based on the url
// Use the global get variable to figure out which page we want to display
$page = isset($_GET['page']) ? $_GET['page'] : $defaultpage;
// Here i used a short syntax for if and else. This code above is equal to:
//
// if (isset($_GET['page'])) {
//    $page = $_GET['page'];
// } else {
//    $page = $defaultpage;
// }

// Hardcoded list of available pages + the title each page should show
$pages = [
    'home' => [
        'title' => 'Welcome to my site',
        'file' => 'home.php'
    ],
    'about' => [
        'title' => 'About me',
        'file' => 'about.php'
    ]
];

// See if the requesed page is a available page by looking inside $pages
if (isset($pages[$page])) {
    $page = $pages[$page];
}
else {
    $page = $pages[$defaultpage];
}
// $page is now overwritten with an associative array containing
// both 'title' and 'file' for content.

// Let us prepare a variable containing the requested page.
$file = dirname(__FILE__)."/contents/".$page['file'].".php";

// If the file doesn't exist, stop execution with an error message
if (!file_exists($file)) {
    exit('<h1>Page not found');
}
?>
<!doctype html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <title><?php echo $page['title']; ?></title>
    <?php require 'navigation.php'; ?>
</head>
<body>
    ...
    <div id="content">
    <?php include($file); ?>
    </div>
    ...
</body>
</html>

I am not sure why you have included you navigation file in the head tag, but i assume you just misplaced it.

You should use <?php include 'nameOfFile.php'?> to include a php file in another

This can be used it will work find i guess..

    <?php
      include('test.php') //this is how you can add an external php 

      /*but its recommended to use require rather than include as it                                
      throws error to the browser which is really a serious threat*/

     require('test.php')

   ?>

All the best..!!!