/*
Usage:
$parsehtml(file,N).tag
Explanation:
Gets the text between Nth <tag></tag>'s
If the Nth tag doesn't exist, it will return '0'
If you wanted to get the title of a html file, you would use: $parsehtml(file,1).title, not: $parsehtml(file,1).<title>
Example file:
x.html contains:
<x>test</x>
<x>test2</x>
<x>test3</x>
<x3><x2>t</x2></x3>
<x4 test="xyz">xyz</x4>
Examples:
$parsehtml(x.html,1).x = test
$parsehtml(x.html,2).x = test2
$parsehtml(x.html,3).x = test3
$parsehtml(x.html,1).x2 = t
$parsehtml(x.html,1).x3 = <x2>t</x2>
$parsehtml(x.html,1).x4 = xyz
needs mirc 6.14 or above because of the error handling.
*/
alias parsehtml {
var %p = /< $+ $prop $+ [^<>]*>(.*)<\/ $+ $prop $+ [^<>]*>/, %f = $1, %n = $2, %i = 0, %r
if (!$isfile(%f)) { return 0 }
if ($fopen(parsehtml)) { .fclose parsehtml }
.fopen parsehtml %f
while (%i <= %n) {
.fseek -r parsehtml %p
var %f = $fread(parsehtml)
inc %i
if (%i == %n) {
%r = $regml(1)
break
}
}
.fclose parsehtml
if (!%r) { %r = 0 }
return %r
:error
reseterror
if ($fopen(parsehtml)) { .fclose parsehtml }
}