FileMaker Custom Function for HTML Entities

August 29, 2011

HTML Entities

Just today I needed to decode HTML encoded text in FileMaker. I thought this must have been done many times before, so I tried to search for a suitable custom function at BrianDunning.com and FMFunctions.com. After checking few functions I found one that seemed pretty good. Written in 2009 by Fabrice Nordman and named HTMLencoded2Text, this custom function was converting my imported text OK at first sight.

See the custom function at FMFunctions.com:

http://www.fmfunctions.com/functions_display_record.php?functionId=178

But later I discovered that this function still does not convert all characters. For instance the “latin small letter s with caron” which is often used in Czech was missing.

I didn’t want to add missing characters by try-and-fix approach, so I looked for some well formatted list of named html character entities on the web, and finally found this website: http://alumnus.caltech.edu/~leif/namedchar.html

It was easy to modify the HTML to leave only a single consistent table there, which I could copy and paste to Numbers. Then I saved the Numbers document as Excel and converted to FileMaker. Now I was in an environment where I feel at home… ;-)

Finally, I ended up with a sample file that generated an updated version of HTMLencoded2Text custom function, taking all the named character entity definitions from the database.

Feel free to download the file and use it not only as a generator of this custom function, but also as an inspiration for solving your own issues like this one.

Click here to download the sample file.

{ 8 comments… read them below or add one }

Donovan August 30, 2011 at 8:56 am

Great example HOnza. Way to spread the gospel of code generation. No one should have to type that stuff out by hand! I also appreciate how you still allow the function to generate its results dynamically when possible.

Reply

HOnza September 13, 2011 at 4:04 pm

I have just optimized the custom function to run about 4 times faster when processing 33 kilobytes of text and millions times faster when processing 1.4 MB of text.

Re-download the sample file to get the updated custom function.

I am also going to post a video of the optimization as soon as I get some time to cut it…

Reply

HOnza September 14, 2011 at 12:29 am

One more update and correction.
I have made a mistake in the optimization, causing the function to not work right when used multiple times in the same context (the $HTMLencoded2Text_deep variable was persisting across multiple calls). If you have already downloaded the optimized version, please re-download the file with this bug fixed.

Correction: it’s about 8 times faster on the 33KB text and maybe not millions but only several hundreds times faster on the 1.4MB text ;-)

Reply

ian moree November 27, 2011 at 12:21 pm

HOnza!!

how did you learn all that you know man. I just am blown away by all you guys and your determination to learn so much with FILEMAKER!

do you have a LIST of what you did to learn what you have?

And your Custom Function rocks.

-ian

Reply

HOnza November 28, 2011 at 2:08 am

:-) Thanks, Ian!

No, I don’t have a specific list but I think you can do well if you follow these few rules:

1) Keep your mind open for new knowledge and never think you know enough already
2) Never give up when you see a technical issue (everything is possible, if something seems impossible it just means you have not figured the way yet)
3) Attend FileMaker DevCon, Pause On Error and other events where you can meet others and listen what they say
4) Always try to come up with even better solution
5) Keep doing it consistently 20+ years ;-)

Rodney June 22, 2012 at 8:42 am

I have not gotten the function to work. I am trying to use it to remove all the HTML references and display text in a field. Is this what this function should do. Below is an example of what I am trying to cleanup. I appreciate your help.
Rodney

From 2-5-09

Hello Ryan – I completely forgot about approving the assay – but I did so today. And, yes, everything turned out very well and as we expected. The rest of the experience was fantastic – could not have been easier or more convenient and we look forward to working with your service.Thank you for the great service and checking back with us.-Michael

Reply

HOnza July 7, 2012 at 11:45 am

This function is not supposed to remove HTML (translate HTML to plain text). It’s only purpose is to translate HTML entities to binary encoded unicode characters.

Reply

Heather McCue November 8, 2012 at 6:17 pm

You wrote … “It was easy to modify the HTML to leave only a single consistent table there, which I could copy and paste to Numbers. Then I saved the Numbers document as Excel and converted to FileMaker. Now I was in an environment where I feel at home…”

I appreciated your sharing of the multiple transformations employed to convert a valuable resource into a functional source. Made me feel not alone with my occasional tendency to follow seemingly convoluted paths to achieve the most desirable result (i.e., little to no future effort required).
HV

Reply

Leave a Comment