Brian Dunning's FileMaker Custom Functions

TextToHTMLEntities ( theString )

converts a string into HTML entities

  Average rating: 3.4 (85 votes) Log in to vote

Tom Catchesides   Tom Catchesides - Show more from this author
Tom Catchesides
http://www.catchesides.co.uk

Share on Facebook Share on Twitter

  Sample input:
TextToHTMLEntities( "HTML does not like characters such as é & ô" )
  Sample output:
"HTML does not like characters such as é & ô"

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

HTML files can only contain a limited set of characters. This custom functions encodes special characters that fall outside this set into HTML entities which - when rendered in a browser - will display the special character.

 

Comments

Sean   Sean, Private
Jan 21, 2010
I would not replace every space with &nsp; as that just gets messy. It's double spaces you have to worry about. So turn [ " " ; " " ] ; into [ "  " ; "  " ]; which makes the second space a no-breaking space. There are also several issues with characters that may need to be escaped. You may not always want ¶, ", and & converted to an html entity. Just my 2¢.
 
Philip McGeehan   Philip McGeehan, SMD Ltd
Apr 7, 2020
I needed to add a condition for an apostrophe.
Because substitutions are preformed in the order they are listed - the ampersand must be the first condition!
If it was not the first condition:
"'" gets turned into "'" then "'" gets turned into "'"

Hopefully this will save other people getting as confused as I did!
 
Philip McGeehan   Philip McGeehan, SMD Ltd
Apr 7, 2020
"'" gets turned into "& apos ;" then "& apos ;" gets turned into "& amp ; apos ;"
(ignore the spaces above, they are added to stop them getting converted)
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: