Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting HTML tags to uppercase

Status
Not open for further replies.

mentalste

Programmer
Nov 23, 2005
4
GB
Im having a lot of dificulty in building a perl script that converts HTML tags from lowercase to uppercase. e.g. from <head> to <HEAD>. Please Help Me.

Thank you
 
For the sake of simplicity I would write something like this:
Code:
while(<>){
[tab]s/<head>/<HEAD>/g;
[tab]s/<\/head>/<\/HEAD>/g;
[tab]print;
}
And so on for each tag name you need to convert.

Mike

I am not inscrutable. [orientalbow]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Code:
[b]#!/usr/bin/perl[/b]

while (<DATA>) {
  s/(<\/?[^>]+)/uc $1/ge;
  print;
}

__DATA__
blah blah <body background=blah.jpg> blah blah
blah <head> Blah blah blah... </head> blah
blah blah <td span=3>blah</td> blah blah blah

Kind Regards
Duncan
 
Trouble with that one Duncs is that it will uppercase any filenames and if the filename is case sensitive it could all fail.


Trojan.
 
but it looks like your regexp won't work except for the simplest one word html tags Trojan.
 
I must admit... i was thinking the same as Kevin

Kind Regards
Duncan
 
I was thinking more of having the perl script ask for the name of an HTML file and, once entered, having the perl script convert all the lowercase HTML tags in the HTML file to uppercase in one process. if that helps.

Thanks

Steve
 
As a matter of interest, why are you trying to do this? HTML 4.0 recommends writing tags in lowercase (though it *technically* doesn't matter), and it's required that they be lowercase in XHTML.
 
I've recently started using perl and i am experimenting with it. I came up with this idea to see how perl interacts with HTML.
 
Kevin (and Duncs),

All html tags are only one word.
It is true that my regex won't uppercase the attributes but then that was not asked for.
If we wish to address the attributes as well then that is another question but I, like Ishnid, have to wonder about the sanity of this type of operation for two reasons.
Firstly, as Ishnid rightly points out, the general preferrence for tags would be to lowercase them, not uppercase them.
Secondly there are many modules that are designed for processing html and maybe we should be looking at those if we need anything more complex than the uppercasing or lowercasing of the tag alone.



Trojan.
 
yes, that is very true Trojan, html tags are really one word. The attributes could be thought of as a seperate component of the tags.
 
I'm only practising with Perl. It's not an operation i'm likely to use for anything else.
On the question of the sanity of the operation, look af my name! :D
 
:)

Mike

I am not inscrutable. [orientalbow]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Code:
<HTML><BODY>
<H1>This will break badly</H1>
<SCRIPT>

    var x = 1;
    var y = 2;
    if ( x[red]<y[/red] ) {
      alert( 'spot the problem?' );
    }
</SCRIPT></BODY></HTML>

Yours,

fish

[&quot;]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.[&quot;]
--Maur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top