473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 2561

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 programación 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: krammer | last post by:
Hello, I have the following questions that I have not been able to find any *good* answers for. Your help would me much appreciated!, fyi, I am a Java XML guy and I have no experience with SGML...
27
by: EU citizen | last post by:
Do web pages have to be created in unicode in order to use UTF-8 encoding? If so, can anyone name a free application which I can use under Windows 98 to create web pages?
5
by: Nancy | last post by:
I recently completed a web page, "Browser Tests of Entities in 2004". http://www.santagata.us/characters/CharacterEntities.html It shows those characters that work in all of the version 5.2+...
32
by: Wolfgang Draxinger | last post by:
I understand that it is perfectly possible to store UTF-8 strings in a std::string, however doing so can cause some implicaions. E.g. you can't count the amount of characters by length() | size()....
8
by: lorenzo.viscanti | last post by:
X-No-Archive: yes Hi, I've found lots of material on the net about unicode html conversions, but still i'm having many problems converting unicode characters to html entities. Is there any...
6
by: Bill Nguyen | last post by:
I'm getting data from a mySQL database (default char set = UTF-8). I need to display data in Unicode but got only mongolian characters like this: Phạm Thị Ngọc I changed the textbox font to...
2
by: Frantic | last post by:
I'm working on a list of japaneese entities that contain the entity, the unicode hexadecimal code and the xml/sgml entity used for that entity. A unicode document is read into the program, then the...
3
by: Laangen_LU | last post by:
Dear Group, my first post to this group, so if I'm on the wrong group, my apologies. I'm trying to send out an email in Chinese lanuage using the mail() function in PHP. Subject and...
25
by: Simon | last post by:
Hello - I'm working on a team that is planning to add Welsh language support to a large existing IT system which is partially web-based and English-language-only so far. I've heard that 2...
2
by: neovantage | last post by:
hey geeks, I am using a function which convert unicode to entities. So that i can save values into mysql database into entities. This function really helps me when i display the store entity data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.