Page 1 of 1
text between html tags
Posted: Wed Jan 23, 2013 11:38 am
by btotherunner
Hello,
iam new in livecode
I want to select parts of a website.
In this parts i need the Text betwenn the html tags to save the Data in a Datastore.
in PHP i use "substr" and "strpos"
$pos1 = (strpos($content, '<h1 class="fl fBold">')+96);
$pos2 = strpos ($content, '</h1>', $pos1);
$ergebnis1 = substr($content, $pos1, $pos2-$pos1);
how do I solve this in live code?
Greets from Germany!
Re: text between html tags
Posted: Wed Jan 23, 2013 1:10 pm
by Klaus
Hi,
1. welcome to the forum!
2. No idea about PHP, but looks like you want to extract any text between 2 html tags:
<h1 class="fl fBold">bla bala bla...</h1>
-> bla bala bla...
Correct?
Then I would use OFFSET to get the number of the first character of the found string:
...
## tHTMLTEXT holds your html source
## Construct start tag with QUOTES -> <h1 class="fl fBold">
put <h1 class=" & QUOTE & "fl fBold" & QUOTE & ">" into tStartString
put "</h1>" into tEndString
put offset(tStartString,tHTMLTEXT) into tStartChar
put offset(tEndString,tHTMLTEXT) into tEndChar
## "move" offset to the correct position:
add length(tStartString) to tStartChar
put char tStartChar to tEndChar of tHTMLTEXT into tErgebnis
...
Well, this is untested and out of my head, but you get the picture
Check these stacks to get more of the basics of Livecode if neccessary:
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Re: text between html tags
Posted: Wed Jan 23, 2013 9:56 pm
by Simon
I thought it was:
Code: Select all
set the htmlText of fld 1 to "<b>Your HTML text</b>"
put the text of fld 1 into myVar
fld 1 can be hidden
"put the text" returns.. well the text
Ahh, some tags are not handled like the <Title></Title> tag, look up HTMLText in the dictionary for supported tags.
Simon
Re: text between html tags
Posted: Wed Jan 23, 2013 10:29 pm
by snm
Code: Select all
set the htmlText of fld 1 to "<b>Your HTML text</b>"
put the text of fld 1 into myVar
Ahh, some tags are not handled like the <Title></Title> tag, look up HTMLText in the dictionary for supported tags.
And it no works correctly with Unicode characters.
Marek
Re: text between html tags
Posted: Wed Jan 23, 2013 10:49 pm
by Simon
ACII values greater then 255 encoded as "bignum" like #12387; work.
Marek, do you have an example page that does not require a specific font to be installed?
I'd like to define my answers better.
Simon
Re: text between html tags
Posted: Thu Jan 24, 2013 12:37 pm
by Klaus
Hi guys,
In this parts i need the Text between the html tags* to save the Data in a Datastore.
* <> htmltext!
That was his wish, and this can't be done with just "the text of fld X" after setting its HTMLTEXT.
Besides the fact that this won't work with special characters and unicode!
So my approach might come closest
See my post here and the previous one from Simon:
http://forums.runrev.com/phpBB2/viewtop ... 755#p66331
Best
Klaus
Re: text between html tags
Posted: Sat Jan 26, 2013 10:22 am
by snm
Simon, I don't understand what are you asking me about
Simon wrote:Marek, do you have an example page that does not require a specific font to be installed?
I'd like to define my answers better.
Marek
Re: text between html tags
Posted: Sat Jan 26, 2013 8:48 pm
by Simon
Hi Marek,
It's ok I found what I was looking for.
Thanks,
Simon