Skip to main content
jibinanto40792294
Inspiring
Nov 5, 2021 7:12 PM UTC
Answered

Character entity usage

Hello,

Using coldfusion 2016. have some queries related to character entity values.
Tried html equivalent character entity for replacing trademark and apostrphe special characters. Function used is given below.


private any function specialCharUpdate(strData){
// Ampersand
arguments.strData = replacenocase(strData, '&', '&##38;', 'All');
// ™ trademark
// arguments.strData = replace(strData, '™', '&##8482;', 'All');
arguments.strData = replacenocase(strData, '™', ' &##153;', 'All');
// Apostrophe
arguments.strData = replacenocase(strData, '''', '&##39;', 'All');
arguments.strData = replacenocase(strData, '’', '&##39;', 'All');
// Circle
arguments.strData = replacenocase(strData, '®', '&##174;', 'All');
// Copyright
arguments.strData = replacenocase(strData, '©', '&##169;', 'All');
return arguments.strData;
}

 

1) The apostrphe from keyboard ' is getting replaced with '
But another kind of apostrphe ’ is not getting replaced with either ' or «This kind of '’' weird character is received

2) Trade mark symbol ™ is not getting updated with ™ or ™Instead like this 'â„¢'

Q:Can anybody suggest the right way to replace this?

3) Data insertion happens as ? on production environment where as in development environment it gets inserted additional symbol along with question mark symbol.
Both are using same codeset and sam cf version.
Q: What are the chance for different behaviour?

3) is it possible to give array as paramter for replacing
eg: array first parameter contain special data($search) and second array parameter contain code to replace($replace) like in php
str_replace($search, $replace, $description);

    This topic is closed to new replies. Start a new post to keep the conversation going.
    BKBK
    BKBKCorrect answer
    Community Expert
    Nov 14, 2021 6:49 PM UTC

    Did you follow the suggestions? Did that help?

    8 replies

    BKBK
    Community Expert
    Community Expert
    Nov 8, 2021 11:37 AM UTC

    Two things:

    1.  Make sure your ColdFusion server has Unicode encoding.
      To do so, open \bin\jvm.config in a text editor.(Back it up first).
      Does its java.args property include the flag -Dfile.encoding=UTF-8 ?
      If yes, then OK.
      If no, then include the flag, save the file and restart ColdFusion.

    2.  You can find the character entities you need at https://www.toptal.com/designers/htmlarrows/symbols/.
      Use the search function on the site. What you will be looking for are the HTML Code and HTML Entity.

     

    I ran the following test using the values from the web site:

    <cfset testString = "Curly apostrophes: curling left &##8216; and curling right &##8217; <br>
    Apostrophe: &##39; <br>
    Circle: &##9900; <br>
    Trademark: &trade; (from HTML Entity) or &##8482; (from HTML Code)<br>
    Registered Trademark:  &reg; (from HTML Entity) or &##174; (from HTML Code) <br>
    Copyright: &copy; (from HTML Entity) or &##169; (from HTML Code)">
    
    <cfoutput>#testString#</cfoutput>

     

    The result was:

     

     

     

     

    Translate
    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    Nov 14, 2021 6:49 PM UTC

    Did you follow the suggestions? Did that help?

    Translate
    jibinanto40792294
    Inspiring
    Nov 16, 2021 12:51 PM UTC

    Yes, you are correct

    Adding jvm settings and restarting the cf server worked.
    Reading a txt file containing around 1,60,000 records and it contain less than 1000 records with special characters.
    When we read the big size file, the special character is not getting replaced .
    It is working fine with small small size file with few records.

    Translate