This discussion is archived
3 Replies Latest reply: Sep 28, 2013 12:17 PM by fac586 RSS

Conversion to html characters

InoL Guru
Currently Being Moderated

Is there a standard function (in 11.2) to convert special characters to the HTML equivalent? I've been searching for this function, but haven't found one yet.

 

I do not mean a URL escape:

 

SQL> select utl_url.escape('é') coded from dual;

CODED

----------

%BF

 

 

but a function that would return

 

SQL> select some_function('é') coded from dual;

CODED

----------

é



I need to send html emails using a mail package that uses utl_smtp.data. This strips the special characters.

I know this can be solved by using utl_smtp.write_raw_data. Since it is a standard mail package, my options are limited in modifying that package. Instead of modifying the package, I am looking into converting the email html text to encoded html first.


Thanks


Ino


  • 1. Re: Conversion to html characters
    Mike Kutz Expert
    Currently Being Moderated

    Look at APEX_ESCAPE.HTML function.  (It also gives reference to sys.htf.escape_sc.)

    This returns the string:  'é'

     

    Personally, I'd look at the APEX_EMAIL package.

     

    MK

  • 2. Re: Conversion to html characters
    InoL Guru
    Currently Being Moderated

    Thanks Mike. I forgot to look at the Apex packages. However, our Apex version (4.1) doesn't seem to have this package yet. The underlying htf.escape_sc doesn't do so much either:

     

     

    SQL> select htf.escape_sc('é') coded from dual;

    CODED

    --------

    é

     

    And yes, I did want to use APEX_MAIL, but it cannot use inline attachments (which I need in this case):

    Change content-disposition in email attachment

    So, I use another mail package that we have, but that one converts the input to us7ascii.

     

    I'll probably end up using my own conversion table. I don't really need every character (for now anyway), just the vowels with accents.

  • 3. Re: Conversion to html characters
    fac586 Guru
    Currently Being Moderated

    MikeKutz wrote:

     

    Look at APEX_ESCAPE.HTML function.  (It also gives reference to sys.htf.escape_sc.)

    This returns the string:  'é'

    Not always:

    SQL> select apex_escape.html('é') from dual;
    
    APEX_ESCAPE.HTML('É')
    --------------------------------------------------------------------------------
    é
    

    There's no explanation for this in the APEX API documentation, but there is in the wwv_flow_escape package spec:

    -- In addition, the function may escape unicode characters if the database NLS

    -- character set is not UTF-8 or if the REQUEST_IANA_CHARSET http header

    -- variable is set to something different than UTF-8 (which is the default). If

    -- unicode escaping applies, these characters are escaped via &#xHHHH; where

    -- HHHH is the unicode hex code.

    So you won't get Unicode characters escaped if—like me—you're using a UTF-8 (AL32UTF8) database.

     

    InoL wrote:

     

    Is there a standard function (in 11.2) to convert special characters to the HTML equivalent? I've been searching for this function, but haven't found one yet.

    utl_i18n.escape_reference, but I don't think it does exactly what you're looking for. It appears to convert some accented letters to their basic Roman equivalent rather than HTML numeric character references. You could try using asciistr to convert Unicode characters to code units, then regexp_replace to turn the code units into HTML numeric references:

    SQL> with t as (
      2    select 'Café Vårdö' s from dual)
      3  select
      4      s
      5    , apex_escape.html(s) apex
      6    , utl_i18n.escape_reference(s, 'us7ascii') i18n
      7    , regexp_replace(asciistr(s), '(\\)([0-9A-F]{4})', '&#x\2;') asciistr
      8  from
      9*      t
    SQL> /
    
    S            APEX             I18N             ASCIISTR
    ------------ ---------------- ---------------- --------------------------------
    Café Vårdö   Café Vårdö       Cafe Vårdo  Café Vårdö
    

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points