首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >decodedURI在HTML中不能正确显示

decodedURI在HTML中不能正确显示
EN

Stack Overflow用户
提问于 2011-08-19 05:35:35
回答 1查看 137关注 0票数 2

我有一个用perl编码的字符串,使用

代码语言:javascript
复制
uri_escape ($string);

然后,我将其传递给Javascript,并通过

代码语言:javascript
复制
fileName = decodeURIComponent ($somevariable);

然后,我对变量发出警报,字符串显示正确(在本例中)

代码语言:javascript
复制
his33a;Cell-Line_Fly-biotin-tagged-H33;Tissue_embryo-derived-cell-line;Developmental-Stage_late-embryonic-stage;Compound_80-600-mM;extract_soluble-fraction;sampling_time_point_1-–-2-hours;DNA-tiling-array;Rep-2;Dmel_r54;modENCODE_2523;GSM333854.wiggle

但是,在HTML中,它显示为

代码语言:javascript
复制
his33a%3BCell-Line_Fly-biotin-tagged-H33%3BTissue_embryo-derived-cell-line%3BDevelopmental-Stage_late-embryonic-stage%3BCompound_80-600-mM%3Bextract_soluble-fraction%3Bsampling_time_point_1-%E2%80%93-2-hours%3BDNA-tiling-array%3BRep-2%3BDmel_r54%3BmodENCODE_2523%3BGSM333854.wiggle
EN

回答 1

Stack Overflow用户

发布于 2011-08-19 09:41:23

Perl/URI::Escapeuri_escape和JavasScript的encodeURIComponent不做同样的事情。为了保证兼容性,请使用CPAN的JavaScript模块:

代码语言:javascript
复制
use 5.014;
use warnings;
use JavaScript;
use URI::Escape;

my $rt = JavaScript->create_runtime();
my $cx = $rt->create_context();
my $string = 'his33a;Cell-Line_Fly-biotin-tagged-H33;Tissue_embryo-derived-cell-line;Developmental-Stage_late-embryonic-stage;Compound_80-600-mM;extract_soluble-fraction;sampling_time_point_1-–-2-hours;DNA-tiling-array;Rep-2;Dmel_r54;modENCODE_2523;GSM333854.wiggle';

# Perl:
say uri_escape($string);
# his33a%3BCell-Line_Fly-biotin-tagged-H33%3BTissue_embryo-derived-cell-line%3BDevelopmental-Stage_late-embryonic-stage%3BCompound_80-600-mM%3Bextract_soluble-fraction%3Bsampling_time_point_1-%E2%80%93-2-hours%3BDNA-tiling-array%3BRep-2%3BDmel_r54%3BmodENCODE_2523%3BGSM333854.wiggle

# JavaScript:
$cx->eval(qq|
function escape_uri(string) { return encodeURIComponent(string) }
|);
say $cx->call('escape_uri', $string);
# his33a%3BCell-Line_Fly-biotin-tagged-H33%3BTissue_embryo-derived-cell-line%3BDevelopmental-Stage_late-embryonic-stage%3BCompound_80-600-mM%3Bextract_soluble-fraction%3Bsampling_time_point_1-%C3%A2%C2%80%C2%93-2-hours%3BDNA-tiling-array%3BRep-2%3BDmel_r54%3BmodENCODE_2523%3BGSM333854.wiggle
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7114430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档