473,791 Members | 3,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to convert entities into unicode

245 New Member
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 into web page n it shows special charactor easily. Here is the function code

Expand|Select|Wrap|Line Numbers
  1. function charset_decode_utf_8($string) {
  2.           /* Only do the slow convert if there are 8-bit characters */
  3.         /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
  4.         if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string))
  5.             return $string;
  6.         // decode three byte unicode characters
  7.         $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e","'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'",$string);
  8.         // decode two byte unicode characters
  9.         $string = preg_replace("/([\300-\337])([\200-\277])/e","'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",$string);
  10.         return $string;
  11.     }
  12.  
But when i explort data into csv file then it shows entities instead of converting the entities into unocde. So is there a way to convert these entities into unicode while exploring data into csv file.?

Kindly help me out to sort out my problem as i am badly stuck in it and i have less time.


kind regards,
Mohsin Rafique
Dec 8 '09 #1
2 4882
Atli
5,058 Recognized Expert Expert
Hey.

Are you converting the unicode string to HTML entities before saving them in your database?
If so, you shouldn't. The data you save in the database should be neutral so you don't have to "decode" it if you use it for some other purpose than it was originally intended for. (Like say, if you want to save data meant for HTML in CSV form.)

It would be best to save the unicode string in it's original form and encode the entities on the way out, when you print it to the HTML page. That way you won't have to "decode" it for your CSV.
Dec 8 '09 #2
neovantage
245 New Member
Thanks sir but i have found the solution of this. One simple function decode the entities into unicode and that is
html_entity_dec ode()
But thanks again for your help. I am really very thankful to you
Dec 9 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
14333
by: davihigh | last post by:
My Friends: I am using std::ofstream (as well as ifstream), I hope that when i wrote in some std::string(...) with locale, ofstream can convert to UTF-8 encoding and save file to disk. So does ifstream. Something I found shows that, I need to have a proper codecvt to set it. I need more information, maybe a small piece of code sample. Thank you!
2
10398
by: Albert | last post by:
How can I convert some html entities (polish) to a character which I can use in a javascript alert? The entities are: ń ę ń ą ż ś ć
7
2542
by: ngocviet | last post by:
I have a text like this: "Thuyền Và Biển" How to convert it to: "Thuyền Và Biển" Please help!
2
2804
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 program sorts out every doublet and the hexadecimal unicode code is extracted, but I dont know a way to find the xml or sgml-entity equivalent to the unicode code. Anyone who could give me a pointer? Best regards
3
8748
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 mailbody are stored as Unicode entities (eg. 註)
1
4337
by: Alexander.Veit | last post by:
Hallo, does anyone know how to convert HTML Entities into UCS2-String (Value). For example: I need to convert Sułowska 43 (value in mysql database) to a unicode string with the specified polish character(s) (Polish is just a example).
8
19857
by: Steven D'Aprano | last post by:
I have a string containing Latin-1 characters: s = u" and many more..." I want to convert it to HTML entities: result => "© and many more..." Decimal/hex escapes would be acceptable:
3
5208
by: ldng | last post by:
Hi, I'm looking for a way to convert en unicode string encoded in UTF-8 to a raw string escaped with HTML Entities. I can't seem to find an easy way to do it. Quote from urllib will only work on ascii (which kind of defeat the purpose imho) and escape from cgi doesn't seems to do anything with my string.
3
2070
by: bsagert | last post by:
Some web feeds use decimal character entities that seem to confuse Python (or me). For example, the string "doesn't" may be coded as "doesn’t" which should produce a right leaning apostrophe. Python hates decimal entities beyond 128 so it chokes unless you do something like string.encode('utf-8'). Even then, what should have been a right-leaning apostrophe ends up as "’". The following script does just that. Look for the string "The...
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9987
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.