JavaScript or PHP code needed to replace words

Discussion in 'Web Development' started by shanali4, Sep 8, 2008.

  1. shanali4

    shanali4 New Member

    Joined:
    Jun 7, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. shanali4

    shanali4 New Member

    Joined:
    Jun 7, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
  3. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    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>
    
     
  4. juresh

    juresh New Member

    Joined:
    Sep 11, 2008
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    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/javascript-string-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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice