Capitalize first letter of a string (preceded with special characters) - PHP(字符串的第一个字母大写(前面有特殊字符)-PHP)
问题描述
我想要大写如下的字符串:
¿"hello"?
我希望我的函数返回
¿"Hello"?
我尝试过regex和preg_Match,但没有成功... 这是我之前的问题,与这个问题相关: "preg_match is matching two characters when it should only match one"
谢谢大家!
推荐答案
可以使用preg_replace_callback:
preg_replace_callback('/^([^a-z]*)([a-z])/i', function($matches){
return $matches[1] . strtoupper($matches[2]);
}, '¿"hello"?');
// ¿"Hello"?
这篇关于字符串的第一个字母大写(前面有特殊字符)-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!