我有一个像这样的字符串
$str = "one two three four five six seven eight nine
One Two Three Four Five Six Seven Eight Nine
oNE tWO tHREE fOuR fIVE sIX sEVEN eIGHT nINE
ONE TWO THREE FOuR FIVE SIX SEVEN EIGHT NINE";
使用PHP语言,模式可以将其转换为此字符串:
$str = "1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9";
答案 0 :(得分:1)
对于 PHP ,您可以执行以下操作:
$string = "one two three four five six seven eight nine
One Two Three Four Five Six Seven Eight Nine
oNE tWO tHREE fOuR fIVE sIX sEVEN eIGHT nINE
ONE TWO THREE FOuR FIVE SIX SEVEN EIGHT NINE";
$replace = array(0,1,2,3,4,5,6,7,8,9);
$search = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
echo str_ireplace($search, $replace, $string);
正如 Fred -ii- 在他的评论str_ireplace
中所指出的那样,它可以解决不敏感的问题。