How to encode cyrillic characters for URL and then decode them?

前端 未结 3 810
情深已故
情深已故 2021-01-18 17:17

I have a form on one page:

One of the input fi

3条回答
  •  灰色年华
    2021-01-18 17:42

    Try that in your script (index.cgi) :

    use Encode;
    

    Then...

    $search_string = decode_utf8( $search_string );
    

    Another idea (if you want to create a UTF8-friendly hash of your CGI input) :

    require Encode;
    require CGI;
    my $query = CGI ->new;
    my $form_input = {};  
    foreach my $name ( $query ->param ) {
      my @val = $query ->param( $name );
      foreach ( @val ) {
        $_ = Encode::decode_utf8( $_ );
      }
      $name = Encode::decode_utf8( $name );
      if ( scalar @val == 1 ) {   
        $form_input ->{$name} = $val[0];
      } else {                      
        $form_input ->{$name} = \@val;  # save value as an array ref
      }
    }
    

    Taken from : http://ahinea.com/en/tech/perl-unicode-struggle.html

提交回复
热议问题