text between html tags

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
btotherunner
Posts: 1
Joined: Wed Jan 23, 2013 11:33 am

text between html tags

Post by btotherunner » Wed Jan 23, 2013 11:38 am

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!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: text between html tags

Post by Klaus » Wed Jan 23, 2013 1:10 pm

Hi,

1. welcome to the forum! :D

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 :D

Check these stacks to get more of the basics of Livecode if neccessary:
http://www.runrev.com/developers/lesson ... nferences/


Best

Klaus

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: text between html tags

Post by Simon » Wed Jan 23, 2013 9:56 pm

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 :D

Ahh, some tags are not handled like the <Title></Title> tag, look up HTMLText in the dictionary for supported tags.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: text between html tags

Post by snm » Wed Jan 23, 2013 10:29 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: text between html tags

Post by Simon » Wed Jan 23, 2013 10:49 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: text between html tags

Post by Klaus » Thu Jan 24, 2013 12:37 pm

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 8)

See my post here and the previous one from Simon:
http://forums.runrev.com/phpBB2/viewtop ... 755#p66331
:D


Best

Klaus

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: text between html tags

Post by snm » Sat Jan 26, 2013 10:22 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: text between html tags

Post by Simon » Sat Jan 26, 2013 8:48 pm

Hi Marek,
It's ok I found what I was looking for.

Thanks,
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply