由于 preg_split 函数返回的是一个数组,如果要重新添加句号,可以使用 implode 函数将数组中的元素拼接成一个字符串,并在每个元素后面加上句号。例如:

$str = 'This is a sentence. This is another sentence.';
$arr = preg_split('/\./', $str);
$new_str = implode('. ', $arr) . '.';
echo $new_str;

输出:

This is a sentence. This is another sentence.
PHP preg_split 后如何重新添加句号

原文地址: https://www.cveoy.top/t/topic/npAa 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录