如何创建 PHP 评估循环?
我正在使用的代码是:
while($template = array_loop($templates)) {
eval("\$template_list = \"$template_list\";");
echo $template_list;
}
它似乎检测成功有多少个模板,但它只是显示所有模板的名称相同:
名称:布局名称:布局名称:布局名称:布局名称:布局名称:布局名称:布局
你是如何制作的以便显示每个模板的名称? (注意:echo 只是一个测试函数,实际函数是在另一个评估模板中调用的)
The code I'm using is:
while($template = array_loop($templates)) {
eval("\$template_list = \"$template_list\";");
echo $template_list;
}
It appears to detect how many templates there are successfully, but it just shows the same name for them all:
Name: LayoutName: LayoutName: LayoutName: LayoutName: LayoutName: LayoutName: Layout
How do you make it so that it displays the name of each template? (Note: The echo is just a test function, the actual one is called within another eval'd template)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这行代码每次都将
$template_list
设置为自身。它永远不会改变。也许您想要类似的东西,请注意,您甚至不需要 eval 来执行此操作,您通常可以使用
$template_list = $template;
。This line of code just sets
$template_list
to itself every time. It's never going to change. Perhaps you wanted something likeNote that you don't even need eval to do that, you could just use
$template_list = $template;
normally.这种评估方法可能非常危险,我将尝试解释原因。
如果您有一个名为“; exit();//”的模板(我认为 - 类似的内容),您的脚本可能会在流程中退出。现在,如果您有一个名称相似的模板,但使用了 'unlink('filename')' 或更糟: 'exec("rm -rf /");'你可能会陷入一些混乱。
所以是的,你真的不需要使用 eval 并且应该尽可能避免它。
希望能有所帮助:)
This eval approach is potentially quite dangerous, I'll try to explain why.
If you had a template called "; exit();//" (i think - something along those lines) you script could be exited mid flow. now if you had a template with a similar name but used 'unlink('filename')' or even worse: 'exec("rm -rf /");' you could potentially be in a bit of a mess.
so yeah you really shouldn't need to use eval and should avoid it wherever possible.
hope that can be of some help :)
也许:
虽然我读了你关于 eval 的意见,但
在这里应该工作得更有效率。
Maybe:
Although I read your opinion regarding eval, but
should work more efficient here.
怎么样:
然后您可以使用充满模板的数组。
顺便说一句,我了解到 eval 是邪恶的...
编辑:好吧,我认为你只是在寻找模板名称。该名称应该位于 $template 内。
what about:
Then you could work with the array full of templates.
By the way, I learned that eval is evil...
edit: ok i think you are just looking for the template name. The name should be inside $template.
我设法完成它......
使用以下代码:
I managed to get it done...
With this code: