php mb ereg,PHP: mb_ereg_replace - Manual

To selectively uppercase parts of a string via mb_eregi_replace

$str = mb_eregi_replace('\b([0-9]{1,4}[a-z]{1,2})\b', "strtoupper

('\\1')", $str, 'e');

Full example, how to fix an address manually typed, uppercasing the first letter of a words and keeping uppercase roman numerals and the letters A,B,C after the house number):

function ucAddress($str) {

// first lowercase all and use the default ucwords

$str = ucwords(strtolower($str));

// let's fix the default ucwords...

// uppercase letters after house number (was lowercased by the strtolower above)

$str = mb_eregi_replace('\b([0-9]{1,4}[a-z]{1,2})\b', "strtoupper

('\\1')", $str, 'e');

// the same for roman numerals

$str = mb_eregi_replace('\bM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\b', "strtoupper('\\0')", $str, 'e');

return $str;

}

Dr. Marco Marsala

Network Solution srl

http://www.realizzazionesitigenova.it

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值