我想使用preg_replace
或ereg replace
之类的内容来翻译下面的一段短语:
This is one This is two This is three This is four
到列表中,例如下面的列表:
请注意,我只是在大写字母之前定位空格。
答案 0 :(得分:0)
AnimationTime
答案 1 :(得分:0)
我会使用preg_match_all
,http://php.net/manual/en/function.preg-match-all.php。
preg_match_all('~([A-Z][^A-Z]+)~', 'This is one This is two This is three This is four', $sentances);
print_r($sentances[1]);
输出:
Array
(
[0] => This is one
[1] => This is two
[2] => This is three
[3] => This is four
)
演示(也是正则表达式的解释):https://regex101.com/r/zW4iW0/1
PHP演示:http://sandbox.onlinephpfunctions.com/code/2be9da124130c2259d10336837ff9c8405ce495a
另请注意,大多数(所有?)e
reg PHP函数(和修饰符)都已弃用。
警告 自PHP 5.3.0起,此函数已被弃用。非常不鼓励依赖此功能。