Solved

Translate Word Smart Quotes submitted in form data?

Posted on 2008-10-29
5
431 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now