There are currently 3 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
1276 2
【函數】js中的html編/解碼函數
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 2/25/15 19:17
function htmlspecialchars(str) {
    str = str.replace(/&/gi, '&');
    str = str.replace(/"/gi, '"');
    str = str.replace(/</gi, '&lt;');
    str = str.replace(/>/gi, "&gt;");
    return str;
}
//alert(htmlspecialchars("<<script>alert(\"I'm a pig.\");</sc"));
function htmlspecialchars_decode(str) {
    str = str.replace(/&quot;/gi, '"');
    str = str.replace(/&lt;/gi, '<');
    str = str.replace(/&gt;/gi, '>');
    str = str.replace(/&amp;/gi, "&");
    return str;
}
/*alert(htmlspecialchars_decode("&amp;lt;script&gt;alert(&quot;I'm a pig.&quot;);&lt;/sc&nbsp;<br>&nbsp;<script>alert('a');</script>"));*/
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 2/25/15 19:18
這兩個函數都不對單引號進行處理。
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 3 Posted at: 2/25/15 19:18
參考字符:http://www.w3cschool.cn/func_string_htmlspecialchars.html
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1276 Replies: 2
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 2/25/15 19:18
Announcements