perl - 是否可以在 Perl 中将 'é' 打印为 '%C3%A9' ?

标签 perl urlencode html-encode

我有一些带重音的字符串,例如“é”,目标是将我的字符串放入 URL,因此我需要将“é”转换为“%C3%A9”

我已经测试了一些模块作为 HTML::EntitieEncodeURI::Encode 但没有成功

实际结果: %C3%83%C2%A9

预期结果: %C3%A9

#!/usr/bin/perl
use strict;
use warnings;
use HTML::Entities;
use feature 'say';
use URI::Encode qw( uri_encode );

my $var = "é";
say $var;

$var = uri_encode( $var );

say $var;

最佳答案

您缺少使用utf8

The use utf8 pragma tells the Perl parser to allow UTF-8 in the program text in the current lexical scope. The no utf8 pragma tells Perl to switch back to treating the source text as literal bytes in the current lexical scope. (On EBCDIC platforms, technically it is allowing UTF-EBCDIC, and not UTF-8, but this distinction is academic, so in this document the term UTF-8 is used to mean both).

Do not use this pragma for anything else than telling Perl that your script is written in UTF-8. The utility functions described below are directly usable without use utf8;.

关于perl - 是否可以在 Perl 中将 'é' 打印为 '%C3%A9' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71165599/

相关文章:

java - 为什么需要对=进行url编码?

xslt - 在 XSLT 2.0 中,为什么没有 fn :decode-for-uri?

php - 处理 URL 中的斜杠 ('/' ) CodeIgniter

asp.net - 跨站脚本和 HTML 编码

security - 你在输入或输出过程中使用 HtmlEncode 吗?

perl - DBIx::Class 插入有很多

perl - 无法在 Centos 6.7 上安装 perl 模块 Email::Sender

c# - & 符号被 HTML 编码为 &。有什么办法可以防止这种情况?

regex - 提取开始和结束之间的单词,\G\K

regex - Makefile 变量 - 替换变量中的空格