从文件中获取变量并将其放入HTML文档中


Getting variables from file and putting them in a HTML document

我正试图在一个名为"post-info.php"的php文件中编写一个数组,它看起来像这样:

<?php
$settings = array(
 'submitter' => 'tester',
 'body' => "How about this: 
&gt; Gigabyte Tri-SLI Liquid Luggage 980s",
);
?>

首先,我希望body是一个多行变量。然后,我希望它被index.php文件调用,通过Markdown解析器,然后显示出来。看起来有点像:

<!DOCTYPE html>
<?php
include 'Parsedown.php';
$postinfo = include 'post-info.php';
$Parsedown = new Parsedown();
?>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="style.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <div class="jumbotron vertical-center">
        <blockquote>
          <div class="post-body"><?php echo $Parsedown->text($postinfo["body"]); ?></div>
          <hr />
          <p class="post-submitter"><?php include($postinfo["submitter"]); ?></p>
        </blockquote>
      </div>
    </div>
  </body>
</html>

那么,我如何让这两个变量出现在这些地方(毫无疑问,我写错了),并让多行变量实际显示为多行?

我不知道Parsedown.php,但对于原始php,如果您使用

include 'post-info.php';
//then you can use your $settings variable defined in post-info.php
echo $Parsedown->text($settings["body"]);

而不是这个

<p class="post-submitter"><?php include($postinfo["submitter"]); ?></p>

尝试使用此

<p class="post-submitter"><?= $settings["submitter"]; ?></p>