需要html entity<->binary转换的。

软件和网站开发以及相关技术探讨
回复
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

需要html entity<->binary转换的。

#1

帖子 eexpress » 2008-04-03 16:24

&#x6587;&#x6863; 这样的是叫html entity吧,包括那些>的。不是的话,就改标题了。 :lol:
想要和utf8二进制互换的方法。

☎ '/usr/share/doc/libhtml-parser-perl/examples/htext' ~/.config/rox.sourceforge.net/ROX-Filer/Bookmarks.xml
似乎是可以?
反向不会。

xml -> utf8
$str =~ s/&#x([[:xdigit:]]+);/chr(hex($1))/ge;
utf8 -> xml 有些问题,思路正确。
$str =~ s/[\x80-]/sprintf("&#x%x;", ord $&)/g;
HTML::Entities or Encode::encode
是现成的,可有空再去看。

或者有其他直接的命令?系统带的?现成的?

--------------------------------
第2种情况:

%E5%AA%92%E4%BD%93 这样的,怎么搞。
$str =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;

代码: 全选

☎  perl html2utf8.pl 
%E5%BA%94%E7%94%A8/%E8%84%9A%E6%9C%AC
应用/脚本
反向这样
$str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
上次由 eexpress 在 2008-04-03 22:31,总共编辑 5 次。
● 鸣学
头像
yaoms
帖子: 4952
注册时间: 2007-10-19 14:51
来自: 深圳

#2

帖子 yaoms » 2008-04-03 16:25

>属于 预定义实体
Nothing 有事请发邮件到 yms541 AT gmail.com
alias 爱慕颇雷尔='mplayer'
头像
zhan
帖子: 1880
注册时间: 2005-08-15 0:04
来自: 南7技校

#3

帖子 zhan » 2008-04-03 16:26

urlencode 和 urldecode 什么的

自己去找脚本
飞得高,飞得低,学习再学习,多少大秘密!
http://zhan.blog.ubuntu.org.cn
头像
yaoms
帖子: 4952
注册时间: 2007-10-19 14:51
来自: 深圳

#4

帖子 yaoms » 2008-04-03 16:27

第二种情况 python和php里都有函数实现
Nothing 有事请发邮件到 yms541 AT gmail.com
alias 爱慕颇雷尔='mplayer'
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#5

帖子 eexpress » 2008-04-03 16:28

urlencode / urldecode in Perl

If you are looking for PHP's urlencode/urldecode equivalent in Perl, you won't find any. But here's what you can do:

Encode:
$str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;

Decode:
$str =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;

测试
● 鸣学
hliang0813
帖子: 31
注册时间: 2005-07-15 12:06

#6

帖子 hliang0813 » 2008-04-12 20:24

如果是PHP中可以用mb_convert_encoding函数的

代码:
<?php
$str = "这是汉字";
$encoded_str = mb_convert_encoding($str, 'HTML-ENTITIES', "UTF-8");
echo $encoded_str;
?>
回复