HTML entity decoding

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 383
Joined: Mon Mar 01, 2010 7:13 pm
Contact:

HTML entity decoding

Post by thatkeith » Mon Mar 17, 2014 10:11 pm

I'm grabbing text from a web page, and this often includes HTML entities, as in this string: "In this second chapter of Ayumi’s biography".
I could simply set the HTMLtext of a field to the grabbed text, but it also contains stuff I want to keep, such as img tags. I could simply run it through a few 'replace' steps, but is there a neater method?
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7394
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: HTML entity decoding

Post by jacque » Tue Mar 18, 2014 5:24 pm

The htmltext isn't lost when it's displayed in a field, so I think I'd just do that because it's the easiest way to translate all the entities. Then when you want to find a particular tag, you can "get the htmltext of fld 1" and use offset or wordoffset to find the tag you're looking for. If you need to collect all the tags of a particular type, include the "skip" parameter in the offset function. That will let you hop through the htmltext very quickly, collecting all the instances as you go.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply