可能捕获PHP回显输出?
问题描述:
所以我有一个功能,例如:
So I have a function such as:
public static function UnorderedList($items, $field, $view = false){
if(count($items) > 0){
echo '<ul>';
foreach($items as $item){
echo '<li>';
if($view){
echo '<a href="'.$view.'id='.$item->sys_id.'" title="View Item">'.$item->$field.'</a>';
}else{
echo $item->$field;
}
echo '</li>';
}
echo '</ul>';
}else{
echo '<p>No Items...</p>';
}
}
此函数循环显示某些项目并呈现无序列表.我想知道的是,如果我愿意的话,是否有可能捕获回声输出.
This function loops over some items and renders a unordered list. What I am wondering is if its possible to capture the echo output if I wish.
我通过做类似的事情来调用使用此功能:
I make a call to use this function by doing something like:
Render::UnorderedList(Class::getItems(), Class::getFields(), true);
这会将无序列表转储到我的页面上.我知道我可以将echo更改为变量并返回该变量,但是我只是好奇是否可以在不修改该函数的情况下捕获echo输出,而只是以某种方式修改对该函数的调用?
And this will dump a unordered list onto my page. I Know I can just change echo to a variable and return the variable but I was just curious if its possible to capture echo output without modifying that function, merely modifying the call to the function in some way?
谢谢!