Wiggins D'Anconia wrote: >Philip Pawley wrote: >>I want to be able to adapt my web-files, as they are being served, so that older >browsers get an xhtml 1.0-transitional version instead of the default xhtml 1.1 >version. This will involve replacing the DOCTYPE declaration and, also, various xhtml >tags to include deprecated html attributes. This needs to happen only for older user >agents such as Netscape 4. >>I imagine this can be done using some search-and-replace module but I can't find a >suitable one. >>Currently, I am using SSI to run a browser-detection script and insert appropriate >css <link ..> and javascript <script..></script> tags. The problem with that is that >it limits me to parsing only a small portion of the html file. Earlier, I asked a >question about re-using variables so that I could use the several SSI includes and >several scripts to do the task. It seems that storing the computed values of the >variables from one script to the next is a bit too involved. (Thanks you, Wiggins >D'Anconia, for your help with that). > >Though it may not be the best way, it is certainly a way. We used to embed special >comments in a file, then in the script, read in the "template" as we called it, >looked for the comment and whenever we found it dropped in whatever content was >necessary. You could do something similar to this... > >-- THIS IS PSEUDO CODE!!! -- > >#!/usr/bin/perl > >my $browser = 'old' if ($ENV{'USER_AGENT'} =~ /Netscape 4/); >my $newtag = '<p />'; > >print "Content-type: text/html\n\n"; > >my $TEMPLATE; >open($TEMPLATE,'/path/to/template.html') or die "Can't open template for reading: $!"; >my @template = <$TEMPLATE>; >close($TEMPLATE); > >foreach my $line (@template) { > if ($line =~ /<!--doctype-->/) { > if ($browser eq 'old') { > # print old version of doctype (or no doc type) > } > } > elsif ($line =~ /<!--oldtag-->/) { > $line =~ /<!--oldtag-->/$newtag/; > print $line; > } >} > > >This only works when comments are on their own line for the doctype and any server >side includes will *NOT* be parsed without special treatment from the web server, or >by getting the template through a second request to the server, but it should give >you some ideas and get you started. Obviously you can use the power of hashes to >handle multiple old tags, etc. > >http://danconia.org
Thanks for the suggestions. The problem is I need to start from someone requesting an html file, not someone calling a script. How can I do it? Thanks, Philip Pawley -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]