doushan6692 2011-08-28 12:03
浏览 55
已采纳

将php文件加载到变量时出现问题(加载php代码的结果而不是代码作为字符串)

I have a site architechure where I assign content to variables and then print them in a master page. My problem is that php code in the sub pages is imported into the variables as strings. Is there anyway to make sure that the code is actually executed and the results is imported in the variables instead?

In the example below the php code in signup_header.php is imorted as a string to $page_header. The result is that "getVerifiedEmail(); ?>" is displayed in the form element instead of the e-mail address.

master.php

<!DOCTYPE HTML>
<html>
<head>
    <?php echo $page_header; ?>
</head>

<body id="home">
    <div class = "container">
       <?php echo $page_content; ?>
    </div>
</body>
</html>

signup.php:

<?php
    $page_content = file_get_contents("./include/signup_content.php");
    $page_header = file_get_contents("./include/signup_header.php");
    include('master.php');
?>

signup_header.php

<script type="text/javascript">
   $(document).ready(function(){
   $('input[name="name"]').attr('value', "<?php echo $idpAssertion->getVerifiedEmail(); ?>");
    });        
</script>

signup_content.php

<section>
    <form class="task" method="POST">
        Name: <input type="text" name="name" maxlength="30" value=""/><br/>
        Email: <input type="text" name="email" value=""/><br/>
        UserId: <input id="userId" type="text" name="userId" value="" /><br/>
    </form>
</section>
  • 写回答

5条回答 默认 最新

  • dqd22496 2011-08-28 12:26
    关注
    <?php
        $page_content = "./include/signup_content.php";
        $page_header = "./include/signup_header.php";
        include('master.php');
    ?>
    

    and

    <!DOCTYPE HTML>
    <html>
    <head>
        <?php include $page_header; ?>
    </head>
    
    <body id="home">
        <div class = "container">
           <?php include $page_content; ?>
        </div>
    </body>
    </html>
    

    that's all

    I hope that signup_content.php contains the similar template only

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?