无法删除右单引号
一直试图从进入 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想您可能会喜欢 Text::Demoronise。
I think you might like Text::Demoronise.
所以,关键是要弄清楚这个角色是什么。一种解决方案是执行以下操作:
一旦您知道该字符是什么,删除它就很简单。
So, the trick is to figure out what the character is. One solution is to do something like this:
Once you know what the character is, removing it is simple.
我将替换行更改为:
这是命令行的结果:
相同的字符串但使用转义的 left 单引号使用原始代码产生了相同的结果。
编辑
我已经清理了输出 - 命令提示符现在只是“$”,并且在输出末尾添加了换行符,这使得更容易查看相关输出。
I changed the substitution line to:
This is my result from the command line:
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.