January 30, 2021
Here's how you can use Laravel's Str
helper to remove double spaces from a string in PHP, using regex:
use Illuminate\Support\Str;
$string = 'Here is my sentence. There are double spaces.';
$newString = Str::of($string)->replaceMatches('/ {2,}/', ' ');
This takes any part of the string that matches {2,}
(a space character occurring two or more times in a row) and replaces it with a single space.
Tufts Meal Plan Wrapped
Mar 2, 2024
Building an e-ink picture frame that displays an iCloud photo album
Jan 9, 2024
2023 in review
Jan 5, 2024
Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iām working on!