[英]What is the equivalent of JavaScript's decodeURIcomponent in PHP?
[英]ruby/rails equivalent to javascript decodeURIComponent?
我有一些內容(html)由於這個javascript(來自此頁面 )而被編碼並發送到我的rails應用程序:
function encode_utf8_b64(string) {
return window.btoa(unescape(encodeURIComponent(string)));
}
對應的js代碼將其恢復原狀是這樣的:
function decode_utf8_b64(string) {
return decodeURIComponent(escape(window.atob(string)));
}
我的問題是,在decodeURIComponent()的ruby中是否有相應的東西? 到目前為止,我有這個讓它成為出路的一部分,但我錯過了decodeURIComponent的最后一步:
CGI::escape(Base64.decode64(string))
URI.unescape可能會有所幫助:
def decode_utf8_b64(string)
URI.unescape(CGI::escape(Base64.decode64(string)))
end
你必須添加必要的rubygem:
require 'uri'
我在ruby 1.9.2上測試了這個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.