Reputation: 89
I have a text file that looks something like this:
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
Is there a way that I can remove all of the spaces after the "?" so it looks something like this (the space amounts are all different throughout the actual text file):
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
Upvotes: 1
Views: 1877
Reputation: 219804
$input = 'What word is on page 9, 4 words from the left on line 15? account';
echo preg_replace('/\?\s+/', '?', $input);
Upvotes: 1
Reputation: 14681
Use a regular expression:
$str = 'What word is on page 9, 4 words from the left on line 15? account';
echo preg_replace('/\?\s+/', '?', $str);
Upvotes: 3