kannada unicode entity code before insert into database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nithinkolekar
    New Member
    • Nov 2010
    • 7

    kannada unicode entity code before insert into database

    DB = Postgres , UTF-8

    Using PHP I am trying to insert Kannada words into database. File has
    Code:
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    tag, inserting properly into database and retrieving properly(same character encoding as entered).

    my requirement is

    - before inserting into database is it possible to get htmlentity like &#3205, &#3206 for the characters. I tried htmlentity,html specialchars nothing works
    - after successful insertion while displaying also both functions not working

    My code
    Code:
    $kanstring = pg_escape_string($_POST['kantext']);
    $array = explode(',', $kanstring);
    foreach ($array as &$arr) {// if textarea contains multiple words
          $data = htmlentities($arr, ENT_COMPAT, 'UTF-8');
                echo "data " . $data . "";
    ...
    Last edited by nithinkolekar; Nov 29 '10, 03:50 PM. Reason: utf characters entered instead of entity code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    somewhere in the comments section of utf8_decode() (or utf8_encode) there are several functions posted that do exactly that.

    Comment

    • nithinkolekar
      New Member
      • Nov 2010
      • 7

      #3
      I tried your suggestion but still not working. I reduced
      the code into single file and removed post action.
      Now testing only one character of first alphabet of kannada . function htmlentities is not returning &#3205.

      Here is my complete code.

      Code:
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
          <head>
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <title>UTF8 to HTML Entity</title>
          </head>
          <body>
               <?php
      
                  $str = "ಅ";
                  $str1 = '';
      
                  echo "Html Entity Decode"."<br>";
      
                  $quotes = html_entity_decode($str, ENT_QUOTES);
                  $noquotes = html_entity_decode($str, ENT_NOQUOTES);
                  $noquotesutf8 = html_entity_decode($str, ENT_NOQUOTES, 'UTF-8');
                  echo "quotes=$quotes, noquotes=$noquotes, noquotesutf8=$noquotesutf8"."<br>";
      
                  echo "Html Entities"."<br>";
                  $quotes = htmlentities($str1, ENT_QUOTES);
                  $noquotes = htmlentities($str1, ENT_NOQUOTES);
                  $noquotesutf8 = htmlentities($str1, ENT_NOQUOTES, 'UTF-8');
                  $noquotesall = htmlentities($str1, ENT_QUOTES, 'UTF-8');
                  echo "quotes='$quotes', noquotes='$noquotes', noquotesutf8='$noquotesutf8',noquotesall='$noquotesall'\n";
              
              ?>
          </body>
      </html>

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I tried your suggestion but still not working
        you didn’t try what I suggested …

        function htmlentities is not returning &#3205.
        why should it? HTML entities are named, after all.

        Comment

        • nithinkolekar
          New Member
          • Nov 2010
          • 7

          #5
          sorry there was a mistake in code
          Code:
          $str = "ಅ";
          $str1 = '';
          should be
          Code:
          $str = '&# 3205;'; // remove space in between 
          $str1 = 'ಅ';

          I tried following methods utf8tohtml(),ut f8ToUnicodeEnti ties(),_utf8_de code() nothing works and Some functions did not work as erep() is deprecated.

          Function html_entity_dec ode() worked fine when entered &# 3205. I found that htmlentities() is opposite of html_entity_dec ode but it is not working.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            I found that htmlentities() is opposite of html_entity_dec ode but it is not working.
            just to make sure, you know what type of entity htmlentities() returns?

            personally, I’m using utf2html() and I never had problems with it.

            PS. "not working" is not an error description that will help you or me getting it right.

            Comment

            • nithinkolekar
              New Member
              • Nov 2010
              • 7

              #7
              I tried all three different function in your mentioned link but still not getting what was I expecting.

              Because you are well sure about utf2html() I assume there might be some thing about php version 5.3.3. For temporarily I am using var_dump() with mb_convert_enco ding() and trimming string until I found solution.
              Code:
              $str = "ಅ";
              $str =  var_dump(mb_convert_encoding($str, 'HTML-ENTITIES', 'UTF-8'));
              echo $str;

              Comment

              • Laurentiu Turcu
                New Member
                • Jun 2011
                • 1

                #8
                I did what Dormilich said and works fine, only encoded the string when inserted in database with utf8_encode();

                Comment

                Working...