[英]Getting variables from file and putting them in a HTML document
我试图在一个名为“ post-info.php”的php文件中编写一个数组,如下所示:
<?php
$settings = array(
'submitter' => 'tester',
'body' => "How about this:
> 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.