468,250 Members | 1,604 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,250 developers. It's quick & easy.

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 htmlspecialchars but
they don't convert "","","" etc. Should I write a custom function? I
can't find a native one. Thanks. :-)
Sep 1 '06 #1
6 2351

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

I made up this:

<?php

$stringa = "' < ";
$convmap = array(0x80, 0xff, 0, 0xff);
$str = mb_encode_numericentity($stringa, $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_decimal_value here?

http://radekhulan.cz/item/php-script...ory/apache-php

Thanks!
Sep 1 '06 #2

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? :-)
Sep 1 '06 #3
*** 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 programacin web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Sep 2 '06 #4
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($string,ENT_QUOTES);

$entity_array = array(
'&iexcl;' ='¡',
'&cent;' ='¢',
'&pound;' ='£',
'&yen;' ='¥',
'&ordf;' ='ª',
'&laquo;' ='«',
'&deg;' ='°',
'&cedil;' ='¸',
'&raquo;' ='»',
'&iquest;' ='¿',
'&Agrave;' ='À',
'&Aacute;' ='Á',
'&Acirc;' ='Â',
'&Atilde;' ='Ã',
'&Auml;' ='Ä',
'&Aring;' ='Å',
'&AElig;' ='Æ',
'&Ccedil;' ='Ç',
'&Egrave;' ='È',
'&Eacute;' ='É',
'&Ecirc;' ='Ê',
'&Euml;' ='Ë',
'&Igrave;' ='Ì',
'&Iacute;' ='Í',
'&Icirc;' ='Î',
'&Iuml;' ='Ï',
'&ETH;' ='Ð',
'&Ntilde;' ='Ñ',
'&Ograve;' ='Ò',
'&Oacute;' ='Ó',
'&Ocirc;' ='Ô',
'&Otilde;' ='Õ',
'&Ouml;' ='Ö',
'&times;' ='×',
'&Oslash;' ='Ø',
'&Ugrave;' ='Ù',
'&Uacute;' ='Ú',
'&Ucirc;' ='Û',
'&Uuml;' ='Ü',
'&Yacute;' ='Ý',
'&THORN;' ='Þ',
'&szlig;' ='ß',
'&agrave;' ='à',
'&aacute;' ='á',
'&acirc;' ='â',
'&atilde;' ='ã',
'&auml;' ='ä',
'&aring;' ='å',
'&aelig;' ='æ',
'&ccedil;' ='ç',
'&egrave;' ='è',
'&eacute;' ='é',
'&ecirc;' ='ê',
'&euml;' ='ë',
'&igrave;' ='ì',
'&iacute;' ='í',
'&icirc;' ='î',
'&iuml;' ='ï',
'&eth;' ='ð',
'&ntilde;' ='ñ',
'&ograve;' ='ò',
'&oacute;' ='ó',
'&ocirc;' ='ô',
'&otilde;' ='õ',
'&ouml;' ='ö',
'&divide;' ='÷',
'&oslash;' ='ø',
'&ugrave;' ='ù',
'&uacute;' ='ú',
'&ucirc;' ='û',
'&uuml;' ='ü',
'&yacute;' ='ý',
'&thorn;' ='þ',
'&yuml;' ='ÿ',
'&fnof;' ='ƒ',
'&rang;' ='〉',
'&loz;' ='◊',
'&quot;' ='"',
'&amp;' ='&',
'&lt;' ='<',
'&gt;' ='>',
'&OElig;' ='Œ',
'&oelig;' ='œ',
'&Scaron;' ='Š',
'&scaron;' ='š',
'&Yuml;' ='Ÿ',
'&circ;' ='ˆ',
'&tilde;' ='˜',
'&euro;' ='€');
//
return preg_replace(
"/&[A-Za-z]+;/",
" ",
strtr($inner_string,$entity_array) );

}

but when the data arrives to the db through $_POST, it arrives as
regular LATIN, not encoded :-(((
Sep 2 '06 #5
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:
--->""", not "&apos;". I tried htmlentities and htmlspecialchars 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/

Sep 2 '06 #6
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:
--->""", not "&apos;". I tried htmlentities and htmlspecialchars but
they don't convert "*","è","é" etc. Should I write a custom function? I
can't find a native one. Thanks. :-)
Take a look at

http://us3.php.net/manual/en/function.utf8-encode.php

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.

http://us2.php.net/ord

HTH,
--
Benjamin D. Esham
bd*****@gmail.com | AIM: bdesham128 | Jabber: same as e-mail
"I'm tall," said Ron inconsequentially.
— an amusing-without-context line from HBP
Sep 2 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by krammer | last post: by
27 posts views Thread by EU citizen | last post: by
5 posts views Thread by Nancy | last post: by
32 posts views Thread by Wolfgang Draxinger | last post: by
8 posts views Thread by lorenzo.viscanti | last post: by
6 posts views Thread by Bill Nguyen | last post: by
3 posts views Thread by Laangen_LU | last post: by
25 posts views Thread by Simon | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.