Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Web Development (http://www.go4expert.com/forums/web-development-forum/)
-   -   JavaScript or PHP code needed to replace words (http://www.go4expert.com/forums/javascript-php-code-replace-words-t13624/)

shanali4 8Sep2008 11:16

JavaScript or PHP code needed to replace words
 
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

shanali4 8Sep2008 11:55

Re: JavaScript or PHP code needed to replace words
 
Plz help

oogabooga 9Sep2008 01:31

Re: JavaScript or PHP code needed to replace words
 
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>


juresh 4Oct2008 12:53

Re: JavaScript or PHP code needed to replace words
 
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


All times are GMT +5.5. The time now is 16:16.