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

时间:2015-02-10 00:16:03

标签: php html string variables markdown

我试图在一个名为" 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>

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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

而不是这个

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

尝试使用此

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