Skip to content

Instantly share code, notes, and snippets.

@darkterminal
Last active February 18, 2022 19:15
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 darkterminal/89c2ddf88431cfa5bd8ae641a761d788 to your computer and use it in GitHub Desktop.
Save darkterminal/89c2ddf88431cfa5bd8ae641a761d788 to your computer and use it in GitHub Desktop.
Normalize Whitespace Characters using PHP
<?php
//grepper php normalize whitespace characters
function normalizeWhitespaceCharacters( $string )
{
$stepOne = htmlentities($string);
$stepTwo = trim(preg_replace('/(&nbsp;)+|\s\K\s+/','', $stepOne));
$final = html_entity_decode($stepTwo);
return $final;
}
//end grepper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment