无法删除右单引号

发布于 2024-11-27 03:08:26 字数 442 浏览 10 评论 0原文

一直试图从进入 Perl 表单的数据中删除正确的单引号,但未成功。如果我将文本:( Can't Be Dodged ) 粘贴到表单中,它永远不会删除正确的单引号。我尝试了不同的编码和转义 Unicode 方法,但似乎都不起作用。

以下是我正在处理的内容。

#!/usr/bin/perl
use strict;
use CGI::Carp qw( fatalsToBrowser carpout);
use CGI '-utf8';
my $q = CGI->new;
my $buffer = $q->param( 'q' );
print "Content-Type: text/html; charset=UTF-8", "\n\n";
$buffer =~ s/[\'\`\.]//g;
$buffer =~ s/’//sg;
print "$buffer";

Been trying to remove a right single quotation mark from data coming into a Perl form unsuccessfully. If I paste the text: ( Can’t Be Dodged ) into the form it never removes the right single quotation mark. I've tried different methods of encoding and escaping the Unicode and nothing seems to work.

Below is what I'm working with.

#!/usr/bin/perl
use strict;
use CGI::Carp qw( fatalsToBrowser carpout);
use CGI '-utf8';
my $q = CGI->new;
my $buffer = $q->param( 'q' );
print "Content-Type: text/html; charset=UTF-8", "\n\n";
$buffer =~ s/[\'\`\.]//g;
$buffer =~ s/’//sg;
print "$buffer";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁的新欢旧爱 2024-12-04 03:08:26

我想您可能会喜欢 Text::Demoronise

I think you might like Text::Demoronise.

十六岁半 2024-12-04 03:08:26

所以,关键是要弄清楚这个角色是什么。一种解决方案是执行以下操作:

for my $c (split //, $buffer) {
    printf "[$c]: %x\n", ord $c;
}

一旦您知道该字符是什么,删除它就很简单。

So, the trick is to figure out what the character is. One solution is to do something like this:

for my $c (split //, $buffer) {
    printf "[$c]: %x\n", ord $c;
}

Once you know what the character is, removing it is simple.

吃不饱 2024-12-04 03:08:26

我将替换行更改为:

$buffer =~ s/[\'\’\.]//g;

这是命令行的结果:

$ ./test.pl q="( Can’t Be Dodged )"
Content-Type: text/html; charset=UTF-8

( Cant Be Dodged )
$ 

相同的字符串但使用转义的 left 单引号使用原始代码产生了相同的结果。

编辑

我已经清理了输出 - 命令提示符现在只是“$”,并且在输出末尾添加了换行符,这使得更容易查看相关输出。

I changed the substitution line to:

$buffer =~ s/[\'\’\.]//g;

This is my result from the command line:

$ ./test.pl q="( Can’t Be Dodged )"
Content-Type: text/html; charset=UTF-8

( Cant Be Dodged )
$ 

The same string but using an escaped left single quote produced the same result using the original code.

Edit

I've cleaned up the output - the command prompt is now just '$', and there is a newline added to the end of the output, this makes it easier to see the relevant output.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文