Perl - 验证从网页表单输入的汉字? [英] Perl - Validate Chinese character input from web page form?

查看:25
本文介绍了Perl - 验证从网页表单输入的汉字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Perl 脚本接受并处理来自网页表单中文本字段的输入.它是为网页的英文版本编写的,运行良好.

My Perl script accepts and processes input from a text field in a form on a web page. It was written for the English version of the web page and works just fine.

还有一个中文版的页面(一个单独的页面,不是两种语言在同一页面上),现在我需要我的脚本来处理它.此页面上的用户输入应为中文.

There is also a Chinese version of the page (a separate page, not both languages on the same page), and now I need my script to work with that. The user input on this page is expected to be in Chinese.

预计需要在 UTF-8 中工作,我添加了

Expecting to need to work in UTF-8, I added

use utf8;

这在英文页面上继续正常运行.

This continues to function just fine on the English page.

但是,例如,为了定义一个使用汉字进行比较的字符串变量,我必须使用 utf-8 编码保存 Perl 脚本本身.一旦我这样做,我就会收到可怕的 500 服务器错误.

But in order to, for example, define a string variable for comparison that uses Chinese characters, I have to save the Perl script itself with utf-8 encoding. As soon as I do that, I get the dreaded 500 server error.

很明显,我的做法是错误的,任何有用的指导将不胜感激/

Clearly I'm going about this wrong and any helpful direction will be greatly appreciated/

谢谢.

编辑 - 请参阅下面我的澄清帖子.

EDIT - please see my clarification post below.

推荐答案

正确处理 utf8 :

use strict; use warnings;

use utf8;
use open(IO => ':encoding(utf8)');
binmode $_, ":utf8" for qw/STDOUT STDIN STDERR/;

open(my $fh, '<:utf8', '/file/path'); # if you need a file-handle

# code.....

检查

这篇关于Perl - 验证从网页表单输入的汉字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆