View::filter闭包函数怎么插个变量进去

浏览:235 发布日期:2021/01/11 分类:ThinkPHP6专区
我需要一个关键词高亮的功能                return View::filter(function($content){
                    return str_replace("op","<span style='color: red'>op</span>",$content);
                })->fetch("index");
这样指定字符串可以,
不过我需要按某个变量替换.比如$keyword;                return View::filter(function($content){
                    return str_replace($keyword,"<span style='color: red'>$keyword</span>",$content);
                })->fetch("index");
这样会提示Undefined variable: keyword



如果闭包函数中
function($content,$keyword) 这里加上$keyword

那么会抛出
Too few arguments to function app\blog\controller\Index::app\blog\controller\{closure}(), 1 passed and exactly 2 expected
最佳答案
评论( 相关
后面还有条评论,点击查看>>