Php 评估函数数据

Php 评估函数数据,php,function,Php,Function,我得到: 我想知道是否有一种方法,在不使用回音通知“text…”、FALSE/TRUE、“some title”的情况下打印出来 只需通知“文本…”,假/真,“某些标题”;没有回声 如果是这样,怎么做呢?返回文本,函数为PHP,因此您必须自己输出结果,或者修改函数,使其输出文本本身。您可以使用此函数: function notification($text, $info = FALSE, $title = FALSE) { global $layout_name; return

我得到:

我想知道是否有一种方法,在不使用回音通知“text…”、FALSE/TRUE、“some title”的情况下打印出来

只需通知“文本…”,假/真,“某些标题”;没有回声


如果是这样,怎么做呢?

返回文本,函数为PHP,因此您必须自己输出结果,或者修改函数,使其输出文本本身。

您可以使用此函数:

function notification($text, $info = FALSE, $title = FALSE) {
    global $layout_name;
    return '<div class="SmallBox"><div class="MessageContainer"><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="'.($info ? "Valid" : "Error").'Message"><div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/'.(!$info ? 'attentionsign.gif' : 'valid.png').');" /></div><b>'.(!$title ? (!$info ? 'Wystąpiły następujące błędy:' : 'Sukces!') : $title).'</b><br/>'.$text.'</div><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div></div></div>';
}

现在,如果使用此函数并传递$content变量,它将在函数外部更改$content。请注意,在php中,通过在变量$VAR之前添加一个&来传递引用。

否,不能使用eval。但是如果你说你会使用$content。。。分配,然后修改函数以执行此操作

function notification($text, $info = FALSE, $title = FALSE, &$content) {
    global $layout_name;
    $content .= '<div class="SmallBox"><div class="MessageContainer"><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="'.($info ? "Valid" : "Error").'Message"><div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/'.(!$info ? 'attentionsign.gif' : 'valid.png').');" /></div><b>'.(!$title ? (!$info ? 'Wystąpiły następujące błędy:' : 'Sukces!') : $title).'</b><br/>'.$text.'</div><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div></div></div>';
}

这样做相当愚蠢。但是对于惰性,如果所有应用程序在全局范围内共享$content输出变量,那么它就可以工作。阅读:无论以前在哪里定义,都需要全局$content。

这就是我想要达到的目标。我怎么能做到呢?我知道,但我不是真的用echo——我用的是$content.=notification$text、$info、$title。。。然后回显$content;因此,我不想每次都写$content.=函数之类的东西,而是只使用函数。我听说可以使用PHP函数-eval来实现,但不知道如何实现。没有办法避免使用函数echo-?@icktoofay你是对的,但它的概念是相同的,而不是OP想要的!Isarius,我认为通过引用传递一个变量可以实现您想要实现的目标。因此,您可以使用$content向函数中添加另一个var,并使用变量发送内容,然后在函数中执行所有操作更新我的答案,如果您不了解任何内容,请告诉我。谢谢。&before$content参数意味着什么?我知道这不是最好的方法。但我见过一些脚本,比如vBulletin或MyBB,它们通过eval函数调用错误函数,所以我想我也可以这样做:。您可以在eval中封装很多东西。这只是include的另一个名称。但我不知道它如何有效地应用于这项任务。我敢肯定,它是用于模板或其他不同的东西在那些公告板脚本。
function notification($text, $info = FALSE, $title = FALSE, &$content) {
    global $layout_name;
    $content .= '<div class="SmallBox"><div class="MessageContainer"><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="'.($info ? "Valid" : "Error").'Message"><div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/'.(!$info ? 'attentionsign.gif' : 'valid.png').');" /></div><b>'.(!$title ? (!$info ? 'Wystąpiły następujące błędy:' : 'Sukces!') : $title).'</b><br/>'.$text.'</div><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div></div></div>';
}
function notification($text, $info = FALSE, $title = FALSE) {
    global $layout_name;
    global $content;
    $content .= '<div class="SmallBox"><div class="MessageContainer"><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="'.($info ? "Valid" : "Error").'Message"><div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/'.(!$info ? 'attentionsign.gif' : 'valid.png').');" /></div><b>'.(!$title ? (!$info ? 'Wystąpiły następujące błędy:' : 'Sukces!') : $title).'</b><br/>'.$text.'</div><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div></div></div>';
}