将php文件加载到变量中时出现问题(将php代码而不是代码作为字符串加载结果) [英] Problem when loading php file into variable (Load result of php code instead of the code as a string)

查看:111
本文介绍了将php文件加载到变量中时出现问题(将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?

在下面的示例中,signup_header.php中的php代码被作为$ page_header的字符串进行了修饰.结果是"getVerifiedEmail();?>"显示在表单元素而不是电子邮件地址中.

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

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:

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

signup_header.php

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

signup_content.php

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>

推荐答案

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

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

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

仅此而已

我希望signup_content.php仅包含类似的模板

I hope that signup_content.php contains the similar template only

这篇关于将php文件加载到变量中时出现问题(将php代码而不是代码作为字符串加载结果)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆