phpschoolÀÇ ÇູÇÑ°í´Ï´ÔÀÇ ±ÛÀÔ´Ï´Ù.
// HTML Ư¼ö¹®ÀÚ¸¦ º¯È¯
String.prototype.htmlChars = function () {
var str = ((this.replace('"', '&')).replace('"', '"')).replace('\'', ''');
return (str.replace('<', '<')).replace('>', '>');
}
// ÁÂ¿ì °ø¹é¾ø¾Ö´Â ÇÔ¼ö
String.prototype.trim = function () { return this.replace(/(^s*)|(s*$)/g, ""); }
// ¿ÞÂÊ °ø¹é¾ø¾Ö´Â ÇÔ¼ö
String.prototype.ltrim = function () { return this.replace(/^s*/g, ""); }
// ¿À¸¥ÂÊ °ø¹é¾ø¾Ö´Â ÇÔ¼ö
String.prototype.rtrim = function () { return this.replace(/s*$/g, ""); }
// ű׸¸ Á¦°Å
String.prototype.stripTags = function () {
var str = this;
var pos1 = str.indexOf('<');
if (pos1 == -1) return str;
else {
var pos2 = str.indexOf('>', pos1);
if (pos2 == -1) return str;
return (str.substr(0, pos1) + str.substr(pos2+1)).stripTags();
}
}
// ´ë¼Ò¹®ÀÚ ±¸º°ÇÏÁö ¾Ê°í ´Ü¾î À§Ä¡ ã±â
String.prototype.ipos = function (needle, offset) {
var offset = (typeof offset == "number")?offset:0;
return str.toLowerCase().indexOf(needle.toLowerCase(), offset);
}
// ´ë¼Ò¹®ÀÚ ±¸º°ÇÏÁö ¾Ê°í µÚ¿¡¼ºÎÅÍ ´Ü¾îÀ§Ä¡ ã±â
String.prototype.ripos = function (needle, offset) {
var offset = (typeof offset == "number")?offset:0;
return str.toLowerCase().lastIndexOf(needle.toLowerCase(), offset);
}
// ¹®ÀÚ¿À» ¹è¿·Î
String.prototype.toArray = function () {
var len = this.length;
var arr = new Array;
for (var i=0; i<len; i++) arr[i] = this.charAt(i);
return arr;
}
//////////////////////////////////////////////////////////
prototype À¸·Î Á¤ÀǵǾîÀÖ¾î¼...
("<b>test</b>").stripTags();
ȤÀº
var str = " !!!! ";
str = str.trim();
°ú °°ÀÌ »ç¿ë°¡´ÉÇÕ´Ï´Ù.
/////////////////////////////////////////////////////////