function str_replace ( search, replace, subject ) { // Replace all occurrences of the search string with the replacement string
//
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Gabriel Paderni
if(!(replace instanceof Array)){
replace=new Array(replace);
if(search instanceof Array){//If search is an array and replace is a string, then this replacement string is used for every value of search
while(search.length>replace.length){
replace[replace.length]=replace[0];
}
}
}
if(!(search instanceof Array))search=new Array(search);
while(search.length>replace.length){//If replace has fewer values than search , then an empty string is used for the rest of replacement values
replace[replace.length]='';
}
if(subject instanceof Array){//If subject is an array, then the search and replace is performed with every entry of subject , and the return value is an array as well.
for(k in subject){
subject[k]=str_replace(search,replace,subject[k]);
}
return subject;
}
for(var k=0; k<search.length; k++){
var i = subject.indexOf(search[k]);
while(i>-1){
subject = subject.replace(search[k], replace[k]);
i = subject.indexOf(search[k],i);
}
}
return subject;
}
function str_replace(search, replace, subject) {
return subject.split(search).join(replace);
}
взято отсюда
http://derclops.ya.ru/replies.xml?item_no=115&ncrnd=2365
ну и че?
внимательно посмари что Kevin van Zonneveld написал а патом пости свою фигню
больше букав, больше времени, мало смысла
Ага, тока у него массивы передавать можно =)
его фигня работает, а в отличии от Kevin van Zonneveld.
Спасибо! помогло)
ОЧЕНЬ ОЧЕНЬ ПЛОХОЙ КОД((( Такие коды никуда не годятся. Слишком громоздка и хреново понятно.
Спасибо, подрочил!
Тема сисек не раскрыта
Отправить комментарий
Приветствуются комментарии:- Полезные.
- Дополняющие прочитанное.
- Вопросы по прочитанному. Именно по прочитанному, чтобы ответ на него помог другим разобраться в предмете статьи. Другие вопросы могут быть удалены.
P.S. Лучшее "спасибо" - не комментарий, как все здорово, а рекомендация или ссылка на статью.Для остальных вопросов и обсуждений есть форум.