unicode entities from characters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Platero

    unicode entities from characters

    Hi, is there a way to convert special characters inserted by a user in a
    form INTO unicode entities? The output format should be numeric:
    --->""", not "'". I tried htmlentities and htmlspecialchar s but
    they don't convert "à","è","é" etc. Should I write a custom function? I
    can't find a native one. Thanks. :-)
  • Platero

    #2
    Re: unicode entities from characters


    I need help but I still try, so...

    I made up this:

    <?php

    $stringa = "' < £ ¤ ¥";
    $convmap = array(0x80, 0xff, 0, 0xff);
    $str = mb_encode_numer icentity($strin ga, $convmap, "ISO-8859-1");
    echo $str;

    ?>

    it is quite perfectly working but the first 2 characters are not
    encoded. So: how can I change $convmap to encode the characters in the
    function entity_to_decim al_value here?



    Thanks!


    Comment

    • Platero

      #3
      Re: unicode entities from characters


      by passing a $string I should get another effect too:
      what is NOT a special character should not be encoded...

      Please, can you help me? :-)

      Comment

      • Alvaro G. Vicario

        #4
        Re: unicode entities from characters

        *** Platero escribió/wrote (Fri, 01 Sep 2006 19:29:07 +0200):
        by passing a $string I should get another effect too:
        what is NOT a special character should not be encoded...
        What's a 'special character' and what isn't?



        --
        -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        ++ Mi sitio sobre programación web: http://bits.demogracia.com
        +- Mi web de humor con rayos UVA: http://www.demogracia.com
        --

        Comment

        • Platero

          #5
          Re: unicode entities from characters

          Alvaro G. Vicario ha scritto:
          >
          What's a 'special character' and what isn't?


          hi, a special char can be "à è ì ò ù á ú ó ñ ... " while a non-special
          char is a regular "a e i L "...

          During the last hours the things are getting more complicated:

          I used this function

          function char_to_decimal _ent($string){

          //
          $inner_string = htmlentities($s tring,ENT_QUOTE S);

          $entity_array = array(
          '&iexcl;' ='&#161;',
          '&cent;' ='&#162;',
          '&pound;' ='&#163;',
          '&yen;' ='&#165;',
          '&ordf;' ='&#170;',
          '&laquo;' ='&#171;',
          '&deg;' ='&#176;',
          '&cedil;' ='&#184;',
          '&raquo;' ='&#187;',
          '&iquest;' ='&#191;',
          '&Agrave;' ='&#192;',
          '&Aacute;' ='&#193;',
          '&Acirc;' ='&#194;',
          '&Atilde;' ='&#195;',
          '&Auml;' ='&#196;',
          '&Aring;' ='&#197;',
          '&AElig;' ='&#198;',
          '&Ccedil;' ='&#199;',
          '&Egrave;' ='&#200;',
          '&Eacute;' ='&#201;',
          '&Ecirc;' ='&#202;',
          '&Euml;' ='&#203;',
          '&Igrave;' ='&#204;',
          '&Iacute;' ='&#205;',
          '&Icirc;' ='&#206;',
          '&Iuml;' ='&#207;',
          '&ETH;' ='&#208;',
          '&Ntilde;' ='&#209;',
          '&Ograve;' ='&#210;',
          '&Oacute;' ='&#211;',
          '&Ocirc;' ='&#212;',
          '&Otilde;' ='&#213;',
          '&Ouml;' ='&#214;',
          '&times;' ='&#215;',
          '&Oslash;' ='&#216;',
          '&Ugrave;' ='&#217;',
          '&Uacute;' ='&#218;',
          '&Ucirc;' ='&#219;',
          '&Uuml;' ='&#220;',
          '&Yacute;' ='&#221;',
          '&THORN;' ='&#222;',
          '&szlig;' ='&#223;',
          '&agrave;' ='&#224;',
          '&aacute;' ='&#225;',
          '&acirc;' ='&#226;',
          '&atilde;' ='&#227;',
          '&auml;' ='&#228;',
          '&aring;' ='&#229;',
          '&aelig;' ='&#230;',
          '&ccedil;' ='&#231;',
          '&egrave;' ='&#232;',
          '&eacute;' ='&#233;',
          '&ecirc;' ='&#234;',
          '&euml;' ='&#235;',
          '&igrave;' ='&#236;',
          '&iacute;' ='&#237;',
          '&icirc;' ='&#238;',
          '&iuml;' ='&#239;',
          '&eth;' ='&#240;',
          '&ntilde;' ='&#241;',
          '&ograve;' ='&#242;',
          '&oacute;' ='&#243;',
          '&ocirc;' ='&#244;',
          '&otilde;' ='&#245;',
          '&ouml;' ='&#246;',
          '&divide;' ='&#247;',
          '&oslash;' ='&#248;',
          '&ugrave;' ='&#249;',
          '&uacute;' ='&#250;',
          '&ucirc;' ='&#251;',
          '&uuml;' ='&#252;',
          '&yacute;' ='&#253;',
          '&thorn;' ='&#254;',
          '&yuml;' ='&#255;',
          '&fnof;' ='ƒ',
          '&rang;' ='〉',
          '&loz;' ='◊',
          '&quot;' ='&#34;',
          '&amp;' ='&#38;',
          '&lt;' ='&#60;',
          '&gt;' ='&#62;',
          '&OElig;' ='Œ',
          '&oelig;' ='œ',
          '&Scaron;' ='Š',
          '&scaron;' ='š',
          '&Yuml;' ='Ÿ',
          '&circ;' ='ˆ',
          '&tilde;' ='˜',
          '&euro;' ='€');
          //
          return preg_replace(
          "/&[A-Za-z]+;/",
          " ",
          strtr($inner_st ring,$entity_ar ray) );

          }

          but when the data arrives to the db through $_POST, it arrives as
          regular LATIN, not encoded :-(((

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: unicode entities from characters

            Platero wrote:
            Hi, is there a way to convert special characters inserted by a user in a
            form INTO unicode entities? The output format should be numeric:
            --->"&#34;", not "&apos;". I tried htmlentities and htmlspecialchar s but
            they don't convert "à","è","é" etc. Should I write a custom function? I
            can't find a native one. Thanks. :-)
            AFAIK, custom function is a better option. I have seen the
            uniord() function that I added in to php manual's user note
            <http://in.php.net/ord#46267is been widely used in similar contexts.

            --
            <?php echo 'Just another PHP saint'; ?>
            Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

            Comment

            • Benjamin Esham

              #7
              Re: unicode entities from characters

              Platero wrote:
              Hi, is there a way to convert special characters inserted by a user in a
              form INTO unicode entities? The output format should be numeric:
              --->"&#34;", not "&apos;". I tried htmlentities and htmlspecialchar s but
              they don't convert "à","è","é" etc. Should I write a custom function? I
              can't find a native one. Thanks. :-)
              Take a look at



              Specifically, the second comment, by user rocketman, may help you. (I have
              no idea whether or not his function works, but if it does it might be what
              you're looking for.)

              The ord() function may also help, but be careful! It only works on ASCII
              values, so it may not help at all.

              Convert the first byte of a string to a value between 0 and 255


              HTH,
              --
              Benjamin D. Esham
              bdesham@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
              "I'm tall," said Ron inconsequential ly.
              — an amusing-without-context line from HBP

              Comment

              Working...