【问题标题】:2 Include code into 1 line php sql2 将代码包含到 1 行 php sql 中
【发布时间】:2018-04-04 06:09:26
【问题描述】:

我对以下代码有疑问。如何将 2 个包含的文件放入 1 行包含? 我已经像下面的代码一样尝试过,但没有显示任何内容(空白页)。它应该显示网址。

  • 网址:theme/default/main/index.php(应该是)
  • application-sql-realtime.php =(当用户更改连接到 sql 的主题模板时应显示“默认”或其他任何内容)

    <?php include('./theme/<?php include_once("config/application-sql-realtime.php");?>/main/index.php');?>

Refer image for code

【问题讨论】:

  • 当你得到一个空白页/或 500 检查你的错误日志。第一个?> 关闭PHP 处理。

标签: php sql


【解决方案1】:

include_one 返回boolean

也许可以是这样的:

<?php
$theme = exec("php config/application-sql-realtime.php");
include("./theme/{$theme}/main/index.php");
?>

但我认为你最好把它放在某个类/函数中

<?php
// inside application-sql-realtime.php you declare a function to return theme name eg: getThemeName
include("config/application-sql-realtime.php");
$theme = getThemeName();
include("./theme/{$theme}/main/index.php");
?>

【讨论】:

  • 第一个工作另一个我不知道如何声明但感谢您的时间
  • 只需使用函数将您的代码包装在application-sql-realtime.php 中,而不是使用echo 使用returnphp.net/manual/en/functions.user-defined.php
【解决方案2】:

使用静态或非静态方法创建一个类以检索您需要的值(例如“默认”)。然后你可以在你的字符串中实现这个值来包含第一个文件。下面是一个静态方法调用的例子:

<?php
$val = EgClass::getPathPart();
include('./theme/'.$val.'/main/index.php');
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 2012-05-18
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 2011-05-22
    相关资源
    最近更新 更多