1

我有一个看起来像这样的文本文件:

What word is on page 9, 4 words from the left on line 15?   account
What word is on page 11, 2 words from the left on line 5?   always

有没有办法可以删除“?”之后的所有空格?所以它看起来像这样(整个实际文本文件中的空间量都不同):

What word is on page 9, 4 words from the left on line 15?account
What word is on page 11, 2 words from the left on line 5?always
4

2 回答 2

3

使用正则表达式:

$str = 'What word is on page 9, 4 words from the left on line 15?   account';
echo preg_replace('/\?\s+/', '?', $str);
于 2013-02-11T17:51:24.330 回答
1
$input = 'What word is on page 9, 4 words from the left on line 15?   account';
echo preg_replace('/\?\s+/', '?', $input);

看到它在行动

于 2013-02-11T17:52:19.307 回答