我得到了:
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>';
}
我想知道是否有办法在不使用echo notification('text...', FALSE/TRUE, 'some title');
只有notification('text...', FALSE/TRUE, 'some title');
(没有echo
)?
如果是这样,怎么办呢?
答案 0 :(得分:0)
返回文本并且函数是PHP,因此您必须自己输出结果,或者修改函数以便它自己输出文本。
答案 1 :(得分:0)
您可以改用此功能:
function notification($text, $info = FALSE, $title = FALSE) {
global $layout_name;
echo '<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>';
}
但它仍然回应结果,没有办法避免使用函数echo
。
通过参考
该函数看起来类似于下面的函数,但您应该更改它以满足您自己的需求:
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。请注意,通过引用传递是通过在变量&
之前添加$VAR
在php中完成的。
答案 2 :(得分:0)
不,使用eval
无法完成。但是如果你说你会使用$content .= ...
分配,那么修改你的功能就可以了。
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>';
}
这样做是相当愚蠢的。但是,如果所有应用程序在全局范围内共享$content
输出变量,那么对于懒惰它将起作用。 (阅读:在先前定义的任何地方都需要global $content
。)