in reply to title sub
I assume that your problem lies within the regular expression and not in the CGI-handling, although your question dosen't really make that clear.
I'm taking this regular expression ("RE") from an old shell script called sitemap which did a site map in bash and some GNU tools - you might want to read more on regular expressions in perlre...
# for offline conversion, set this to 1 $offline = 0; undef $/; open( FILE, "< $filename" ) or die "Can't open $filename : $!\n"; $HTML = <FILE>; close FILE; # Note that you can use \2 (or $2) in the new title part # to reference the old title. $HTML =~ s!(.*?<TITLE>)(.*?)(</TITLE>.*)!... new title here ...!ims; ($Left, $Title, $Right) = ($1,$2,$3); # Here, $Left contains everything left of the page title # $Right contains everything right of the page title # and $Title contains the page title # here you could do some more magic to the page title # before assigning it back to $HTML ... if ($offline) { rename $filename, "$filename.backup"; open( FILE, "> $filename" ) or die "Can't create $filename : $!\n" +; print FILE $HTML; close FILE; } else { print FILE; };
As you might (or might not) notice, this code will have problems with malformed HTML or a document that contains two TITLE tags, only the first such tag will get handled. Also, if you have a commented-out TITLE tag, this will also confuse the RE. But as you say that you want to use this in a template, you can craft your template around that, I hope :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: HTML title substitution
by KM (Priest) on Jun 05, 2000 at 23:00 UTC | |
by Corion (Patriarch) on Jun 05, 2000 at 23:08 UTC | |
by KM (Priest) on Jun 05, 2000 at 23:11 UTC |