Forum Moderators: coopster

Message Too Old, No Replies

Simple find 'n' replace

help please!

         

j4mes

8:29 pm on Jan 22, 2005 (gmt 0)

10+ Year Member



Hi,

So, basically I'm trying to code a quick script that will fetch a page from somewhere, replace pre-defined words with other words and present it.

The particular pages in this case are Yahoo!/Hotmail in order to hop the odd filter ;)

Obviously, the find-n-replace would also have to change relative links to absolute, but thats another hurdle.

If anyone could point me in the right direction / throw some sample code at me (extremely welcome), that would be fantastic.

Cheers,

James.

dreamcatcher

6:04 pm on Jan 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about using str_replace() [php.net]?

You could store the words you want to replace in an array alongside words you want to replace them with, then use the above function to do the necessary replacement.

mincklerstraat

6:25 pm on Jan 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



str_replace is very definitely the way to go if it's just simple replacement of words. If you have to do fancy replacements with all sorts of conditions and such, check out regular expressions and preg_replace and its cohorts - not so nice on your processor, and not so easy to learn as str_replace.

j4mes

1:41 pm on Jan 26, 2005 (gmt 0)

10+ Year Member



Fantastic, thank you so much :)