Created
May 23, 2017 08:52
-
-
Save xus/7cf5d016b033dbb48dbb25aac3038e7f to your computer and use it in GitHub Desktop.
Best way to remove whitespaces and linebreaks in 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
// Sometimes the whitespaces contains bullshit and we need to clean this mess. | |
// I saw the light here --> http://heavydots.com/blog/when-the-white-space-became-a-beast | |
// Same with breaklines. | |
$ascii_whitespaces = chr(194).chr(160); | |
$ascii_breaklines = chr(13).chr(10); | |
$to_replace = array ($ascii_whitespaces, $ascii_breaklines); | |
$replace_to = array (' ', ''); | |
$text = $_POST['text']; // YOUR TEXT HERE... | |
//count characters | |
$chars_entered = strlen(strip_tags(str_replace($to_replace, $replace_to, $text))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment