Last active
October 13, 2016 22:22
-
-
Save brendomaciel/ced6e18a6ac6c4ec3623ea54716b32f1 to your computer and use it in GitHub Desktop.
Função para mesclar múltiplos espaços, quebras de linhas ou tabs em um único espaço.
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 | |
function merge_white_spaces($string) { | |
// Remove multiple line breaks | |
$string = preg_replace("/[\n\r]{3,}|[\r\n]{3,}|[\n]{3,}|[\r]{3,}/", PHP_EOL . PHP_EOL, $description); | |
// Remove tabs | |
$string = preg_replace("/\t+/", "", $description); | |
// Remove multiple spaces (the character " " is used instead \s because the second removes line breaks too) | |
$string = preg_replace("/[ ]{2,}/", " ", $description); | |
$string = trim($description); | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment