Advertisement

07.23.2008 at 11:29PM PDT, ID: 23591141
[x]
Attachment Details

Eliminate unprintable characters from mixed character/binary string

Asked by Ray_Paseur in PHP Scripting Language, Regular Expressions

Tags: PHP, REGEX, Character Translation

I have a PHP script that processes a long data string.  The string is read into my script via file_get_contents() from a Word, Powerpoint, Excel, flat text file, etc.  So some of the string is legible clear text and some of it is not so useful binary stuff like CR and LF, and application dependent binary values and just noise, for my purposes.

I want an efficient way to eliminate all the characters EXCEPT these listed below, by translating the non-listed characters into blanks.

Characters I want to KEEP include a-z A-Z 0-9 &!#$%@_ as well as the dot (period) and dash (minus).  Everything else should be converted into a blank.

I'm not worried about multibyte or UTF-16 or anything like that - the ASCII character set, considered as if one byte at a time, will do just fine.

Sample input and output are in the code snippet.  Anybody got a high-performance solution to help translate this stuff?

Many thanks, ~RayStart Free Trial
1:
2:
3:
4:
5:
6:
7:
Input
1...5...10...15...20...
Hello, Bill?<A>3%($$)
 
Output
1...5...10...15...20...
Hello  Bill  A 3% $$
[+][-]07.24.2008 at 12:28AM PDT, ID: 22076758

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 02:54AM PDT, ID: 22077394

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 03:04AM PDT, ID: 22077432

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 04:49AM PDT, ID: 22078004

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 07:30AM PDT, ID: 22079532

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 08:01AM PDT, ID: 22079920

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 08:14AM PDT, ID: 22080075

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, Regular Expressions
Tags: PHP, REGEX, Character Translation
Sign Up Now!
Solution Provided By: ddrudik
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.24.2008 at 09:00AM PDT, ID: 22080608

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906