2012-06-20 67 views

回答

1

可以使用preg_replace_callback做到这一点:

preg_replace_callback('/^([^a-z]*)([a-z])/i', function($matches){ 
    return $matches[1] . strtoupper($matches[2]); 
}, '¿"hello"?'); 

// ¿"Hello"? 
+0

这是解决近,现在我觉得我在与正则表达式,因为当我的字符串是问题,这个函数返回'éstaprueba?'但是'Éstaprueba?'预计... – jprog

+0

这是最终的解决方案发布: http://stackoverflow.com/questions/11133485/using-of-regex-whith-preg-replace-callback/11133597#comment14592579_11133597 – jprog

2

使用preg_replace_callback作为所述ASCII上面的时间,但兼容Unicode:

echo preg_replace_callback('/^(\PL*)(\pL)/u', function($matches){ 
    return $matches[1] . mb_strtoupper($matches[2],'UTF-8'); 
}, '¿"éllo"?'),"\n"; 

输出:“?¿ESTA prueba”

¿"Éllo"? 
相关问题