评估 HTML & 的 PHP EvalPHP [英] PHP Eval that evaluates HTML & PHP

查看:23
本文介绍了评估 HTML & 的 PHP EvalPHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在搞乱模板,我遇到了一种情况,我需要向浏览器回显包含 html & 的模板.php.ini如何评估 PHP 并将其发送到浏览器?

这里有一个例子(main.php):

 

<div id="head"><?php if ($id > 10): ?><H3>大于10!</H3><?php 其他:?><H3>小于10!</H3><?php endif ?>

然后在template.php中:

 

我的模板还允许您从控制器 Smarty 样式注入数据.输出缓冲区是否允许我这样做,然后评估我的 php.ini 文件.理想情况是它首先通过代码并评估所有标签,然后运行 ​​php.ini 文件.这样我就可以使用从我的控制器发送的数据来创建循环和内容.

所以也许是一个更完整的例子:<div id = "容器"><div id = "title">{$title}</div><!-- 这增加了从控制器发送的数据--><div id="head"><?php if ($id > 10): ?><H3>大于10!</H3><?php 其他:?><H3>小于10!</H3><?php endif ?>

谢谢!

解决方案

如果您尝试使用混合的 HTML/PHP 字符串(就像从数据库中,就像我一样)执行此操作,您可以这样做:

eval(' ?>'.$htmlandphp.'<?php ');

更多信息:http://blog.5ubliminal.com/posts/eval-for-inline-php-inside-html/(注意这是一个截至 2014-3-3 的死链接)

I'm messing around with templating and I've run into a situation where I need to echo to the browser a template that contains html & php. How do I evaluate the PHP and send it to the browser?

So here's an example (main.php):

    <div id = "container">
        <div id="head">
            <?php if ($id > 10): ?>
                <H3>Greater than 10!</H3>
            <?php else: ?>
                <H3>Less than 10!</H3>
            <?php endif ?>
        </div>
            </div>

And then in the template.php:

   <?php
           $contents; // Contains main.php in string format
           echo eval($contents); // Doesn't work... How do I do this line??
   ?>

EDIT: My template also allows you to inject data from the controller Smarty-style. Would an output buffer allow me to do this and then evaluate my php. The ideal is that it does a first-pass through the code and evaluates all the tags in first, then runs the php. This way I can create loops and stuff from using data sent from my controller.

So maybe a more complete example: 
    <div id = "container">
            <div id = "title">{$title}</div> <!-- This adds data sent from a controller -->
            <div id="head">
                <?php if ($id > 10): ?>
                    <H3>Greater than 10!</H3>
                <?php else: ?>
                    <H3>Less than 10!</H3>
                <?php endif ?>
            </div>
    </div>

Thanks!

解决方案

In case you are trying to do this with a string of mixed HTML/PHP (like from a database, as I was), you can do it this way:

eval(' ?>'.$htmlandphp.'<?php ');

More info: http://blog.5ubliminal.com/posts/eval-for-inline-php-inside-html/ (note this is a dead link as of 2014-3-3)

这篇关于评估 HTML &amp; 的 PHP EvalPHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆