homepage Welcome to WebmasterWorld Guest from 54.235.39.132
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
replacing a word with a link on whole site
HuhuFruFru




msg:973455
 6:30 pm on Feb 28, 2003 (gmt 0)

i have site with about 550 pages, and i want to put a link on one specific name which is nearly on every page. how do i do this? i can't make make it with notetab because it also replaces that name in the meta tags or in the filenames - and i just want to put a link on that name when it occurs in the body part of a page. is there a trick for this?

 

JamesR




msg:973456
 6:35 pm on Feb 28, 2003 (gmt 0)

I am not seeing anything in note tab that will let you refine the search to just the body. Does this word appear next to other words consistently in the body?

rcjordan




msg:973457
 6:37 pm on Feb 28, 2003 (gmt 0)

Try adding the leading and trailing spaces in your find and replace, ala:

find: " some name "
replace: " <a href>some name</a> "

Depending on your meta construction, you might have trouble there, but the filenames shouldn't be disturbed.

andreasfriedrich




msg:973458
 6:42 pm on Feb 28, 2003 (gmt 0)

I believe the only safe approach would be to use a HTML::Parser [perldoc.com] to parse the files and then replace the word only in ordinary text and not in any tags.

Andreas

HuhuFruFru




msg:973459
 6:43 pm on Feb 28, 2003 (gmt 0)

>Does this word appear next to other words consistently in the body?

no, that's the problem, it appears everywhere in combination with different words.

is there a programm which can do it only for the body? can dreamweaver do it?

ncw164x




msg:973460
 7:06 pm on Feb 28, 2003 (gmt 0)

Dreamweaver can do it but proceed with a little caution. Try a test first on the page which you have open in Dreamweaver and instead of doing just the word or changes you require either choose a complete sentence or the contents of a table including the table tags, this way you are keeping the table the same but only changing the content from either text or text and hyperlinks combined.

<table width="70%" border="0" cellspacing="0" cellpadding="4"><tr>
<td>This is the text I want to change</td>
</tr></table>

Do a find and replace and replace whatever you want changing in the table

<table width="70%" border="0" cellspacing="0" cellpadding="4"><tr>
<td>This is the link I want to add <a href="http://www.mysite.com">HOME</a></td>
</tr></table>

Dreamweaver wil warn you that any changes can't be undone with any pages which are not open

You can also do a find and replace for the head content for any changes you may require

Have Fun

HuhuFruFru




msg:973461
 7:18 pm on Feb 28, 2003 (gmt 0)

ncw164x, i don't understand. the name i want to replace with a link appears on the 500 pages in very diverse variations, there is nearly no single sentence or single tab which appears a second or third time somewhere else. the only thing which helps, is:

1) i want ro replace ALL words on ALL pages
2) i want ro replace all words in the BODY which are visible to the user

so that the word when it appears in the meta tag or in a filename remains untouched, you know what i mean?

how can dreamweaver do this? with the normal "find and replace"-function it can't work because it can't exclude the non-body-part

robertito62




msg:973462
 7:23 pm on Feb 28, 2003 (gmt 0)

Dreamweaver.

If it doesn' work just press control Z, before saving the files.

andreasfriedrich




msg:973463
 7:32 pm on Feb 28, 2003 (gmt 0)

This script will recursively look for html files and replace a certain pattern with some string.


#!/usr/bin/perl -w
#
use strict [perldoc.com];
#
use File::Find [perldoc.com];
use HTML::Parser [perldoc.com];
#
my $r = 0;
my $p = HTML::Parser->new(api_version => 3);
$p->handler( start => sub {
$r=1 if shift eq 'body';
$r=0 if shift eq 'a';
print OUT pop; }, "tagname,tagname,text");
$p->handler( end => sub {
$r=0 if shift eq 'body';
$r=1 if shift eq 'a';
print OUT pop; }, "tagname,tagname,text");
$p->handler( text => sub {
print(OUT shift), return unless $r;
local $_ = shift;
s!$ARGV[1]!$ARGV[2]!go;
print OUT }, "text");
$p->handler( default => sub { print OUT shift }, "text");
#
find(sub [perldoc.com] {
return [perldoc.com] if -d $File::Find::name;
return [perldoc.com] unless $File::Find::name =~ /\.html?$/;
open [perldoc.com] 'OUT', ">$File::Find::name.temp"
or die "Can't open $File::Find::name.temp: $!\n";
$r = 0;
$p->parse_file($File::Find::name)
or die "Can't parse file: $File::Find::name.temp: $!\n";
close [perldoc.com] 'OUT';
rename [perldoc.com]($File::Find::name, "$File::Find::name.orig");
rename("$File::Find::name.temp", $File::Find::name);
}, $ARGV[0] ¦¦ die);

Call it like so:


[*nix]./htmlrep /path/to/html/files name link
[windows]perl htmlrep c:\path\to\html\files name link

A real life example would be


Perl [perl.com] htmlrep c:\path\to\html\files "Aaron C." "<a href=''>Aaron C.</a>"

As you see this works both on GNU/Linux and Windows. If you donīt have it just grab the ActiveState Perl [perl.com] package and install it (Microsoft Installer - just one click). The script will then run without any configuration.

HTH Andreas


Note: The WebmasterWorld posting software deletes spaces preceding the exclamation point "!" character. It also replaces a solid vertical pipe symbol with a broken vertical pipe "¦" symbol. Both of these changes will need to be undone in any code you copy from WebmasterWorld. Make sure to include a space preceding the "!" in mod_rewrite code, and always replace "¦" with a solid vertical pipe.
andreasfriedrich




msg:973464
 7:34 pm on Feb 28, 2003 (gmt 0)

BTW this is smart enough not to turn the link into a link if the name is already a link ;). Does that make sense? It should.

Andreas

HuhuFruFru




msg:973465
 8:05 pm on Feb 28, 2003 (gmt 0)

thank you very much andreasfriedrich! i have never seen such a thing before- i think it's time for studying it :-)

ncw164x




msg:973466
 9:18 pm on Feb 28, 2003 (gmt 0)

HuhuFruFru
Yes your right what your changing is only in the body so that the word when it appears in the meta tag or in a filename remains untouched.
I had to change 15,000 pages because of a word which was trade marked, in meta tags and in also the body of the page. it was used as text and also as part of the hyperlink, it was used in any variation you could think of and many times on each page in different formats. This is different to what your trying to achieve

andreasfriedrich script seems to be the best option and I will study this script as well

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved