AutoHotkey Community

It is currently May 27th, 2012, 11:53 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to strip HTML tags
PostPosted: November 6th, 2005, 10:07 pm 
Offline

Joined: November 3rd, 2004, 8:43 pm
Posts: 34
Waht is the quickest and easiest ways of stripping html tags from a html file so that it is converted to a .txt file?

I could not find anything on this in the help file.

Thanks,
Martin


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2005, 10:32 pm 
Offline

Joined: April 28th, 2004, 1:12 pm
Posts: 349
Taken from my "HTML to BBCode" script-

Code:
Loop, read, code.txt, outputText1.txt
{
string=%A_LoopReadLine%

loop
{

ifinstring,string, <head>
head=1

ifinstring, string, </head>
head=2

ifinstring,string, <script
script=1

ifinstring,string, </script>
script=2

if head=1
{
StringReplace, string, string, %string%,, All
break
}

if script=1
{
StringReplace, string, string, %string%,, All
break
}

StringGetPos, stringpos1, string, <, L1
StringGetPos, stringpos2, string, >, L1

if stringpos1 = -1
break

if stringpos2 = -1
break

stringpos1+=1
stringpos2+=2


removelength:=stringpos2-stringpos1

if removelength <= 0
break

StringMid, texttoremove, string, %stringpos1%, %removelength%

StringReplace, string, string, %texttoremove%,, All

}

fileappend, %string%`n

}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2005, 10:49 pm 
Offline

Joined: November 3rd, 2004, 8:43 pm
Posts: 34
Jon wrote:
Taken from my "HTML to BBCode" script-


That works great except that the following tags are still left in the text

<BR>
</div>

Many thanks,
Martin


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2005, 6:56 pm 
Offline

Joined: April 28th, 2004, 1:12 pm
Posts: 349
You can use stringreplace to either replace them with nothing or to replace them with new lines. e.g.

Code:
StringReplace, string, string, <br>,`n, All


or

Code:
StringReplace, string, string, <br>, , All


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group