Created
April 15, 2024 20:55
-
-
Save fhferreira/47b6f90e0e2f51d11caa1b773a8dbd58 to your computer and use it in GitHub Desktop.
replaced duplicated spaces with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Replacing multiple spaces with a single space simple single line of php code: | |
$output = preg_replace('/\s+/', ' ', $input); | |
//This mean that spaces, tabs or line breaks (one or more) will be replaced by a single space. | |
//Replace multiple spaces with one space: | |
$output = preg_replace('/\s+/', ' ', $input); | |
//Replace one or multiple tabs with one space: | |
$output = preg_replace('/\t+/', ' ', $input); | |
//Replace one or multiple new lines with one space: | |
$output = preg_replace('/\n\r+/', ' ', $input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment