如何创建 PHP 评估循环?

发布于 2024-08-20 09:17:49 字数 313 浏览 5 评论 0原文

我正在使用的代码是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

挽容 2024-08-27 09:17:49
eval("\$template_list = \"$template_list\";");

这行代码每次都将 $template_list 设置为自身。它永远不会改变。也许您想要类似的东西,

eval("\$template_list = \"$template\";")

请注意,您甚至不需要 eval 来执行此操作,您通常可以使用 $template_list = $template;

eval("\$template_list = \"$template_list\";");

This line of code just sets $template_list to itself every time. It's never going to change. Perhaps you wanted something like

eval("\$template_list = \"$template\";")

Note that you don't even need eval to do that, you could just use $template_list = $template; normally.

思慕 2024-08-27 09:17:49

这种评估方法可能非常危险,我将尝试解释原因。

如果您有一个名为“; 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 :)

烦人精 2024-08-27 09:17:49

也许:

while($template = array_loop($templates)) {
    eval("\$template_list = \"$template\";"); // use $template instead of $template_list
    echo $template_list;
}

虽然我读了你关于 eval 的意见,但

$template_list = $template;

在这里应该工作得更有效率。

Maybe:

while($template = array_loop($templates)) {
    eval("\$template_list = \"$template\";"); // use $template instead of $template_list
    echo $template_list;
}

Although I read your opinion regarding eval, but

$template_list = $template;

should work more efficient here.

后eg是否自 2024-08-27 09:17:49

怎么样:

$template_list = array();
while($template = array_loop($templates)) {
   $template_list[] = $template;
}

// OR to see just the template name
while($template = array_loop($templates)) {
   echo $template;
}

然后您可以使用充满模板的数组。

顺便说一句,我了解到 eval 是邪恶的...

编辑:好吧,我认为你只是在寻找模板名称。该名称应该位于 $template 内。

what about:

$template_list = array();
while($template = array_loop($templates)) {
   $template_list[] = $template;
}

// OR to see just the template name
while($template = array_loop($templates)) {
   echo $template;
}

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.

七婞 2024-08-27 09:17:49

我设法完成它......

使用以下代码:

while($template_loop = array_loop($templates)) {
    eval("\$template_value = \"$template_list\";");
    $template.= $template_value;
}

I managed to get it done...

With this code:

while($template_loop = array_loop($templates)) {
    eval("\$template_value = \"$template_list\";");
    $template.= $template_value;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文