Created
February 12, 2020 20:47
-
-
Save erlangparasu/2fcb5771ddc7d06854b9ab6b0f7aa0b4 to your computer and use it in GitHub Desktop.
To strip all non-ASCII characters from the input string
This file contains hidden or 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 | |
| // To strip all non-ASCII characters from the input string | |
| $result = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $string); | |
| // That code removes any characters in the hex ranges 0-31 and 128-255, leaving only the hex characters 32-127 in the resulting string, which I call $result in this example. | |
| // Thanks to https://stackoverflow.com/users/6589057/junaid-masood | |
| // Link: https://stackoverflow.com/questions/1176904/php-how-to-remove-all-non-printable-characters-in-a-string/54072059#54072059 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment