Created
May 20, 2015 04:35
-
-
Save qutek/0a542a24815764464106 to your computer and use it in GitHub Desktop.
[php] Replace special character using preg replace
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 | |
//Remove from a single line string | |
$output = "Likening ‘not-critical’ with"; | |
$output = preg_replace('/[^(\x20-\x7F)]*/','', $output); | |
echo $output; | |
//Remove from a multi-line string | |
$output = "Likening ‘not-critical’ with \n Likening ‘not-critical’ with \r Likening ‘not-critical’ with. ' ! -."; | |
$output = preg_replace('/[^(\x20-\x7F)\x0A\x0D]*/','', $output); | |
echo $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment