Skip to content

Instantly share code, notes, and snippets.

@qutek
Created May 20, 2015 04:35
Show Gist options
  • Save qutek/0a542a24815764464106 to your computer and use it in GitHub Desktop.
Save qutek/0a542a24815764464106 to your computer and use it in GitHub Desktop.
[php] Replace special character using preg replace
<?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