and this would only encode non-plain ascii: $encoded = encode_entities($input, '^\n\x20-\x25\x27-\x7e');