Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

HTML::Entities not working

by vasanthgk91 (Sexton)
on Jun 19, 2013 at 06:56 UTC ( #1039735=perlquestion: print w/ replies, xml ) Need Help??
vasanthgk91 has asked for the wisdom of the Perl Monks concerning the following question:

I passing the data from html page(contactus.html) to cgi page.Every time I passing Other language string as input.Showing wrong length.

use HTML::Entities; use CGI; my $cgi=new CGI; my $message=$cgi->param('message'); $message=decode_entities($message); my $message_fld_length=length($message); print "$message_fld_length";

The same code working... I passing the data from cgi page(contactus.cgi) to cgi page.I passing other language data as input.Here length working good. Can u please give a suggestion.Why input coming from html page na not working decode_entites.

Comment on HTML::Entities not working
Download Code
Re: HTML::Entities not working
by muba (Priest) on Jun 19, 2013 at 08:31 UTC

    I can't reproduce your problem.

    length.htm:

    <html> <body> <form method="POST" action="length.cgi"> <input type="text" name="message" /> <input type="submit" /> </form> </body> </html>

    length.cgi:

    #!perl use strict; use warnings use HTML::Entities; use CGI; my $cgi=new CGI; my $message=$cgi->param('message'); $message=decode_entities($message); my $message_fld_length=length($message); # Obviously, if I call this script as a CGI script, it won't work unle +ss I send the # minimal set of HTTP headers! print "Content-Type: text/html\n\n"; print "$message_fld_length";

    Input: output (expected output)
    Other language: 14 (14)
    &nbsp;: 1 (1)

    What does your HTML look like? What is your input? What output do you expect? What output do you get?

      This is my input: 社論並指,香港及中國輿論反對引渡史諾登,美國實際上已有思想準備「無法引渡」史諾登,中方應創造條件讓美方最終放棄引渡的希望,避免美方將希望寄託在對香港和北京施加愈來愈大的壓力上。 Read more: 世界新聞網-北美華文新聞、華商資訊 - 中國官媒 引渡史諾登 中港都丟臉

      This input i need exact perl length..that decode_entities not working

        The problem seems not to be with HTML::Entities:

        > perl -MHTML::Entities=decode_entities -e "print length decode_entiti +es('&#31038;&#35542;')" 2

        As you've been told before, you will need to find out what encoding the browser uses to send your input data to your script. This is not necessarily easy to enforce. One good approach is to use <meta http-equiv="Content-Type" ... tags on every HTML page, no matter where it is served from.

        I see no entities that would need decoding. What exact output did you expect? What exact output did you get?

        Without knowing what you want, it is hard to know how to get there.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1039735]
Approved by Corion
Front-paged by perlfan
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (18)
As of 2014-09-02 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (25 votes), past polls