Skip to content

Instantly share code, notes, and snippets.

@brendomaciel
Last active October 13, 2016 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendomaciel/ced6e18a6ac6c4ec3623ea54716b32f1 to your computer and use it in GitHub Desktop.
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.
<?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