我想用 html 表单和 Rebol cgi 存储一些数据。我的表格是这样的:
<form action="test.cgi" method="post" >
Input:
<input type="text" name="field"/>
<input type="submit" value="Submit" />
</form>
但是对于像中文这样的unicode字符,我得到了带有百分号的数据的编码形式,例如
%E4%BA%BA
.(这是针对汉字“人”...其作为 Rebol 二进制文字的 UTF-8 形式是
#{E4BABA}
)系统中有没有函数,或者现有的库可以直接解码?
dehex
目前似乎不包括这种情况。我目前正在通过删除百分号并构建相应的二进制文件来手动解码,如下所示:data: to-string read system/ports/input
print data
;-- this prints "field=%E4%BA%BA"
k-v: parse data "="
print k-v
;-- this prints ["field" "%E4%BA%BA"]
v: append insert replace/all k-v/2 "%" "" "#{" "}"
print v
;-- This prints "#{E4BABA}" ... a string!, not binary!
;-- LOAD will help construct the corresponding binary
;-- then TO-STRING will decode that binary from UTF-8 to character codepoints
write %test.txt to-string load v
最佳答案
我有一个名为 AltWebForm 的图书馆编码/解码百分比编码的网络表单数据:
do http://reb4.me/r3/altwebform
load-webform "field=%E4%BA%BA"
该库在此处描述:Rebol and Web Forms .
关于forms - 是否有一个函数可以像从表单一样解码编码的 unicode utf-8 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18331557/