PHP将变量打印到屏幕并且代码停止运行

时间:2015-12-17 18:40:33

标签: php

我正在尝试将Parsedown Extra与Parsedown一起使用(之前从未使用过)。我有代码$_GET所选类别(?cat=0)并设置它的路径&文件名到var。它$_GET的页码很好,但是当我设置文件var时,它只会打印到屏幕上而不会加载我的页面。

//sets the page (category) number for use with array
//also sets the path to the category's pages
if (isset($_GET['cat'])) {
  $catNum = $_GET['cat'];
  $catPath = 'content/' . $pageList[$catNum]['path'];

  echo '<div class="center pageNav">';

  //lists out subpages of catagory
  $pageAmt = count($pageList[$catNum]['pages']);
  for ($i = 0; $i < $pageAmt; $i++) {
    echo '<a href="' . $catPath . $pageList[$catNum]['pages'][$i]['file'] . '">' . $pageList[$catNum]['pages'][$i]['title'] . '</a>';
  };

  echo '</div>';

  //sets path & filename var to selected page: this is the part where it prints the var and doesn't run the rest. The var is pointing to the right file, I checked.
  $page = $catPath . $pageList[$catNum]['mainPage'];
} else {
  $page = 'content/home.md';
};

//parsedown
require 'parsedown/parsedown.php';
require 'parsedown/parsedownextra.php';
echo ParsedownExtra::instance()
  ->setBreaksEnabled(true)
  ->setMarkupEscaped(true)
  ->text($page);

2 个答案:

答案 0 :(得分:1)

你的if语句末尾有一个半冒号。

} else {
  $page = 'content/home.md';
}; <--

答案 1 :(得分:0)

Parsedown采用标记文本并呈现它。在您的示例中,您将$ page(包含字符串,文件名)传递给 - &gt; text($ page)。这会将字符串解析为标记文本,然后呈现它。所以,在你的例子中,你正好看到它在做什么。如果您尝试通过 - &gt;文本运行文件文本,则需要先加载文件内容并传递给Parsedown。