php - PHP 已弃用:函数 create_function()
问题描述
我越来越不推荐使用 PHP:函数 create_function()
使用以下代码:
function fetch_sentence_case($text)
{
return preg_replace_callback(
'#(^|\.\s+|\:\s+|\!\s+|\?\s+)[a-z]#',
create_function('$matches', 'return strtoupper($matches[0]);'),
vbstrtolower($text)
);
}
我试过了
function fetch_sentence_case($text)
{
return preg_replace_callback(
'#(^|\.\s+|\:\s+|\!\s+|\?\s+)[a-z]#',
function($matches) { return strtoupper($matches[0]; },
vbstrtolower($text)
);
}
但它不起作用。
???
解决方案
我确实意识到您可能由于 PHP 版本而受限于这种方法,但请查看箭头函数。
Wadih 上面的评论是正确的。你缺少括号。
推荐阅读
- javascript - 如何在车把文件中打印“body”元素?
- python - 如何打印数字列表及其平均值?
- html - 如何在相对 div 中包含固定栏并完美显示滚动条
- python - `json.dumps` 对于 \u0000 字符的奇怪行为
- kubernetes - Kubernetes 入口服务 NodePort 只监听 tcp6/ipv6 而不是 tcp/ipv4
- dynamics-crm - 重新分配所有者的自定义工作流突然停止工作
- php - 是否有任何算法可以制作具有每一轮独特组合的循环调度?
- flutter - VSCode 飞镖代码自动完成不适用于包
- cassandra - CQL:InvalidRequest:来自服务器的错误:code=2200 [无效查询]
- ios - 我应该为捆绑 ID 提供什么