Solved

Translate Word Smart Quotes submitted in form data?

Posted on 2008-10-29
5
433 Views
Last Modified: 2013-12-25
In the event that someone copies and pastes the contents of a Word document into a web form, I would like to translate the special Word characters to their ASCII equivalent. I found the following statement online...

      $form_fields->{comments} =~ tr/\x91\x92\x93\x94\x96\x97/''""\-\-/;

But I cannot get this to work correctly. For example; when a word that contains a single quote is entered into the form I get the following as a result from the previous statement: client?'s   It translates the character correctly to the ASCII single quote but I'm not sure where the question mark is coming from.
0
Comment
Question by:yamabob217
  • 3
5 Comments
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 100 total points
ID: 22836769
When you display quotes on a browser, you should use """ (without the double-quotes), not the actual quote character.
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 100 total points
ID: 22848338
please post an example of your data
and an example what you expect
0
 
LVL 1

Expert Comment

by:unobserved
ID: 22887680
I would suggest that first you use HTML::Entities to convert all high-bit ascii charatacters to HTML codes.

####################################
use HTML::Entities;
my $clean_input = encode_entities( $input );
####################################

This will convert the MSWord Smart quotes to “ (Left Double Quote) and ” (Right Double Quote) respectively. They will now display properly in a browser.

If your goal was to remove them completely and replace them with regular quotes you could then:
#############################
$clean_input =~ s|“|"|gi;
$clean_input =~ s|”|"|gi;
#############################
0
 
LVL 1

Expert Comment

by:unobserved
ID: 22887709
Also, if you're only worried about quote characters, you also might want to consider ‘ (Left Single) and ’ (Right Single). But the list of entities that will get converted coming out of MSWord goes far beyond just those four. HTML::Entities really is a god send in this case.
0
 
LVL 1

Accepted Solution

by:
unobserved earned 300 total points
ID: 22887718
You can read the documentation for HTML::Entities here
http://search.cpan.org/~gaas/HTML-Parser-3.56/lib/HTML/Entities.pm
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to dynamically set the form action using jQuery.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question