자바스크립트 urlencode(), urldecode(), rawurlencode(), rawurldecode()

2017. 7. 2. 20:00Web



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

php 함수 대타 용 javascript..!


function urlencode(str) {

    str = (str + '').toString();

    return encodeURIComponent(str)

        .replace(/!/g, '%21')

        .replace(/'/g, '%27')

        .replace(/\(/g, '%28')

        .replace(/\)/g, '%29')

        .replace(/\*/g, '%2A')

        .replace(/%20/g, '+');

}


function urldecode(str) {

    return decodeURIComponent((str + '')

        .replace(/%(?![\da-f]{2})/gi, function() {

            return '%25';

        })

        .replace(/\+/g, '%20'));

}


function rawurlencode(str) {

    str = (str + '').toString();

    return encodeURIComponent(str)

        .replace(/!/g, '%21')

        .replace(/'/g, '%27')

        .replace(/\(/g, '%28')

        .replace(/\)/g, '%29')

        .replace(/\*/g, '%2A');

}


function rawurldecode(str) {

    return decodeURIComponent((str + '')

        .replace(/%(?![\da-f]{2})/gi, function() {

            return '%25';

        }));

}


함수 출처: http://phpjs.org