Is there a function to remove all non UTF-8 characters from a string?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have a UTF-8 string that might contain invalid characters, you can use
iconvto remove those. This should work:Making them visible with an arbitrary placeholder is a bit tougher – I can’t think of any easy way to do that, short of walking through every byte and see whether it’s a valid character. The Wikipedia article provides more info on how to do that.