JavaScript or PHP code needed to replace words

Newbie Member
8Sep2008,11:16   #1
shanali4's Avatar
Hi there I need a javascript code which searches a specific word on the whole page and replace it with a specific page. For Example I have a page which word google and i want to replace google with Yahoo.

Plz urgently needed this script. I prefer Javascript or PHP
Newbie Member
8Sep2008,11:55   #2
shanali4's Avatar
Plz help
Ambitious contributor
9Sep2008,01:31   #3
oogabooga's Avatar
I'm not exactly sure what you're looking for, but Javascript has regular expressions.
Here's an example of how to use them:
Code:
<script>
var re = new RegExp("google", "ig");
var s = "xxxxgooglexxxxxxxxxGOOGLExxx";
var r = s.replace(re, "yahoo");
document.write(r);
</script>
Go4Expert Member
4Oct2008,12:53   #4
juresh's Avatar
hey, where r you use this?
i got it.
i think you r making a social networking site (i think so) and you don't want, that somebody use wrong words on your site, if it used then you can replace with any specific word.

take this tut
http://www.tizag.com/javascriptT/jav...ng-replace.php
And
code
Code:
<script type="text/javascript">
function searchPage(word, replaceWord, tagName){
var elems = document.getElementsByTagName(tagName);
for(var i=0; i < elems.length; i++){
if(elems[i].innerHTML = word){
elems[i].innerHTML = replaceWord;
}
}
}
</script>
thanks