如何在php中每隔一个字符设置一次? [英] how to CaPiTaLiZe every other character in php?

查看:86
本文介绍了如何在php中每隔一个字符设置一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在php中使用CaPiTaLiZe $ string,不要问为什么:D

I want to CaPiTaLiZe $string in php, don't ask why :D

我做了一些研究,在这里找到了很好的答案,它们确实帮助了我。
但是,就我而言,我想开始将每个单词中的每个奇数字符(1,2,3 ...)大写。

I made some research and found good answers here, they really helped me. But, in my case I want to start capitalizing every odd character (1,2,3...) in EVERY word.

例如,通过我的自定义函数,我得到的结果为 TeSt eXaMpLe,而我希望得到的结果为 TeSt ExAmPlE。
在第二个示例中看到单词 example以大写字母 E开头吗?

For example, with my custom function i'm getting this result "TeSt eXaMpLe" and want to getting this "TeSt ExAmPlE". See that in second example word "example" starts with capital "E"?

那么,有人可以帮助我吗? :)

So, can anyone help me? : )

推荐答案

这是一个应该起作用的班轮。

Here's a one liner that should work.

preg_replace('/(\w)(.)?/e', "strtoupper('$1').strtolower('$2')", 'test example');

http://codepad.org/9LC3SzjC

这篇关于如何在php中每隔一个字符设置一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆