I want to convert a pattern like "5a " into "5A ". This pattern may appear at the beginning or middle of a larger string. I've tried this:
我想将像“5a”这样的模式转换为“5A”。此模式可能出现在较大字符串的开头或中间。我试过这个:
$string = preg_replace_callback("/(0-9)([a-z]) /", function($matches) {
return $matches[1].strtoupper($matches[2]).' ';
}, $string);
But it doesn't work. No error - the string just stays as "5a ". Can you see where I've gone wrong?
但它不起作用。没有错误 - 字符串只是保持为“5a”。你能看出我出错的地方吗?
1 个解决方案
#1
3
/(0-9)([a-z]) /
should be
应该
/([0-9])([a-z]) /
#1
3
/(0-9)([a-z]) /
should be
应该
/([0-9])([a-z]) /