how to convert entities into unicode

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neovantage
    New Member
    • Aug 2008
    • 245

    how to convert entities into unicode

    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

    Code:
    function charset_decode_utf_8($string) {
    		  /* Only do the slow convert if there are 8-bit characters */
    		/* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
    		if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string))
    			return $string;
    		// decode three byte unicode characters
    		$string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e","'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'",$string);
    		// decode two byte unicode characters
    		$string = preg_replace("/([\300-\337])([\200-\277])/e","'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",$string);
    		return $string;
    	}
    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
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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.

    Comment

    • neovantage
      New Member
      • Aug 2008
      • 245

      #3
      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

      Comment

      Working...