且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP 正则表达式用   替换空格如果它跟随单个字母

更新时间:2022-06-14 23:11:30

preg_replace('/(?<=\b[a-z]) /i', '&nbsp;', $s);

此处的正则表达式执行正向后视确保空格前面是单个字母和单词边界.

The regular expression here performs a positive lookbehind which ensures that the space is preceded by a single letter and a word boundary.