Making anonymous functions from PHP 5.3 work with PHP 5.2

前端 未结 1 1237
终归单人心
终归单人心 2021-01-26 07:55

I have an anonymous functions that I now need to update to be compatible with PHP 5.2. The function (below) takes text and uppercases the first letter of every sentence.

相关标签:
1条回答
  • 2021-01-26 08:26

    preg_replace_callback() as a second argument requires a callable, that is a function itself, not a returned value from a function.

    So just replace, upper_case($input) with upper_case, so it would look like this

    preg_replace_callback('/([.!?])\s*(\w)/', 'upper_case', ucfirst(strtolower($input)));
    
    0 讨论(0)
提交回复
热议问题