首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP打印变量到屏幕,代码停止运行。

PHP打印变量到屏幕,代码停止运行。
EN

Stack Overflow用户
提问于 2015-12-17 18:40:32
回答 2查看 60关注 0票数 1

我试图在Parsedown中使用减价额外 (以前从未使用过)。我有代码$_GET所选类别(?cat=0),并将其路径&文件名设置为var。它的$_GET页面号很好,但是当我设置文件var时,它只是打印到屏幕上,而不加载我的页面。

代码语言:javascript
复制
//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);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-12-19 00:40:58

Parsedown获取标记文本并呈现它。在您的示例中,您将$page (包含字符串,文件名)传递给->text($page)。这会将字符串解析为标记文本,并呈现出来。所以,在你的例子中,你会看到它到底在做什么。如果您试图通过->text运行文件文本,则需要先加载文件内容并传递给Parsedown。

票数 0
EN

Stack Overflow用户

发布于 2015-12-17 18:46:14

在if语句的末尾有一个分号。

代码语言:javascript
复制
} else {
  $page = 'content/home.md';
}; <--
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34341936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档