PDA

View Full Version : CGI Script that replaces words in web pages


Skybly
09-28-2000, 09:48 PM
Hello,

I'd like to offer a service similar to that of www.askjesus.org (http://www.askjesus.org) on my site (although with a completely different theme).

For those of you who don't know the site:
You can specify a URL of your choice there, and it will be "jesusified". This means the site will be displayed, but certain words will be replaced. For example, all occurances of the word "free" are replaced with "holy", "news" with "revelations" etc.

The easiest way to understand what I mean would probably be going to www.askjesus.org (http://www.askjesus.org) and trying it out for yourself :)

Unfortunately, I am a beginner in CGI scripting and have no clue how to do this...
If anyone has any hints for me, I would be soo grateful :)

ciao,
Skybly (skybly@the-witch.de)

brobe
09-29-2000, 12:44 AM
Hi,
I took this out of the YaBB (yet another bulletin board) there are probably other examples of this type of technology but this is the only one i knew off hand. This is a perl representation.

Please take the code lightly ... most of it i am 100% sure of and some of it im not real sure on. This will just show you basicly what needs to be done.
http://www.mp3-search-portal.com/lessons/lesson1.txt

Click there to view source...this takes a template.html in the same folder as that code and replaces certain words with different ones...

hope this helps


note: sorry this does line by line not word by word...it gives you an idea though where to start


[This message has been edited by brobe (edited 09-28-2000).]

Henrik
10-10-2000, 02:39 AM
I don't have time to look at the site but I think i know what you are looking for.
To do this the easy way you will have to install a couple of perl-modules called LWP and URI you can find them at www.cpan.org (http://www.cpan.org)

The basics of the code would look something like this:

use LWP::Simple; #use the LWP module
use CGI; #use the CGI module
$query = new CGI; #make a new cgi object

$address = "http://www.google.com/"; #the address you want to parse
$page = (get $address); #download the page

#Now we will change some words in the page using regexp
$page =~ s/free/holy/g;
$page =~ s/news/revelations/g;
#we are done and it's time to print the page
print $query->header();
print $page;

Thats about it. That the basics. You would need to add some more code to make it more useful. But this works.