Remove Special Characters from Strings That Have Been Copied and Pasted

Screen Shot 2013-07-25 at 3.34.17 PMWhile working on my quote generator api, I realized that many of the quotes we had copied and pasted into the custom post had kept some of the special characters. They characters didn’t show up on the WordPress site that included the posts, but they do show up when I try to access them remotely through the API.

To strip out the special characters, I replaced my ‘return’ on the random quote function from this:

//
  return $message;
}
//

to this:

//
  return preg_replace('/[^(\x20-\x7F)]*/','', $message);
}
//

This worked really well! No special characters show up anymore. A special thanks to this site for giving me the answer I needed!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top