Forum Moderators: open

Message Too Old, No Replies

Replacing words on site.

         

PokeTech

8:27 pm on Oct 19, 2008 (gmt 0)

10+ Year Member



Lets say on my site every page that says "Welcome" on it I want to replace that with "<b>Welcome!</b>". And I'm not getting content from a mysql database or its not in a variable its just on a page. Is there any javascript, PHP code that will allow me to change it so it turns "Welcome" into "<b>Welcome!</b>"?

Help is appreciated.

tangor

2:03 am on Oct 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Many editors out there allow search and replace either folder or site wide. Google "extended search and replace html" for a list of products to do that.

There are other methods via Linux which I do not know, but that's another possibility.

alt131

1:50 pm on Oct 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it depends on when/why/how you want to do this.
# If this is a simple edit on local files then as Tangor suggested, a "search and replace" tool would do it. Search and replace gets a lot of negative comments about time - I just set mine to run during lunch ;)

# If this is a simple edit on remote files it can be done via a script using php's replace functions. This could also be used locally, although personally cannot see the point as there are so many freebie search/replace programs. However, a search will throw up plenty of pre-written scripts.

# If this is to parse and modify the file "on the fly" before serving to a user agent, then a number of programming languages will do it. Again a search will throw up plenty of php egs, and the Php forum [webmasterworld.com] is available to assist.

Trace

2:58 pm on Oct 20, 2008 (gmt 0)

10+ Year Member



You "could" do it with JavaScript, however it is not recommended. You would need to parse the entire content of the page to find the string you want to replace, not very efficient.

For information purposes only, it would look something like this;

document.body.innerHTML = document.body.innerHTML.replace('Welcome', '<b>BLAH BLAH</b>');