加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

大写字符串的第一个字母(以特殊字符开头) – PHP

发布时间:2020-12-13 16:16:55 所属栏目:PHP教程 来源:网络整理
导读:我想把字符串大写如下: ?"hello"? 我想让我的功能回归 ?"Hello"? 我试过regex和preg_match,没有运气…… 这是我之前的问题,与此相关: “preg_match is matching two characters when it should only match one” 谢谢你们! 解决方法 您可以使用 preg_repl
我想把字符串大写如下:

?"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"?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读