簡體   English   中英

從文件獲取變量並將其放入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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM