如何将匹配的regex单词替换为大写的第一个字符


how to replace matched regex word to uppercased first char

我想用另一个单词替换匹配的单词,但需要将一个索引更改为大写的第一个字符
例如:

replace  action='createView' to actionCreateView; 

您可以在regex中使用''u,如下所示:
示例:

statement: if'('$requestData'[['|"]action['|"]'] == ['|"]([a-zA-Z]+)['|"]')  
replacement regex: public function action'u$1()

为什么不这样尝试

$string = 'someStringcreateView';
$action = 'createView';
$replace = 'action'.ucfirst($action);
echo str_replace($action, $replace, $string); //someStringactionCreateView