replacetext and striptext
PHP Code:
function replacetext(text, oldtext, newtext) {
temp.oldlen = oldtext.length();
temp.textdiff = newtext.length() - temp.oldlen;
for (temp.p: text.positions(oldtext)) {
temp.pos = temp.p + temp.textdiff * (temp.index ++);
text = text.substring(0, temp.pos) @ newtext @ text.substring(temp.pos + temp.oldlen);
}
return text;
}
function striptext(text, oldtext) {
return replacetext(text, oldtext, "");
}