简体   繁体   中英

Getting variables from file and putting them in a HTML document

I'm trying to write an array in one php file called "post-info.php", which looks like so:

<?php
$settings = array(
 'submitter' => 'tester',
 'body' => "How about this: 

&gt; Gigabyte Tri-SLI Liquid Luggage 980s",
);

?>

First of all, I want body to be a multi-line variable. Then, I want it to be called by an index.php file, put through a Markdown parser, and then shown. Looks a bit like this:

<!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>

So, how do I get those two variables to show up in those places (no doubt I wrote them wrong) and have the multi-line variable actually show up multi-line?

I don't know Parsedown.php , but for raw php, if you use

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

Instead of this

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

Try to use this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM