note 71644 deleted from ref.iconv by nlopess

From: Date: Fri, 26 Oct 2007 21:00:07 +0000
Subject: note 71644 deleted from ref.iconv by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-131763@lists.php.net to get a copy of this message
Note Submitter: Erel Segal - Rent a Brain ---- If you don't have iconv, you can use MySQL to do the conversion. Note that to do this you have to use MySQL's charset names, which are different than iconv names (e.g. "utf8" instead of "utf-8"). <?php /** * @param $string * @param $from [string] The name of the current character set of $string, in MySQL format (e.g. "utf8", "hebrew"). * @param $to [string] The name of the character set to which you want to convert $string. * @author Erel Segal - Rent a Brain (http://tora.us.fm/rentabrain) * @date 2006-12-10 */ function mysql_iconv($string, $from, $to) { // keep current character set values: $character_set_database = mysql_result(mysql_query("SELECT @@character_set_client"),0,0); $character_set_results = mysql_result(mysql_query("SELECT @@character_set_results"),0,0); mysql_query("SET character_set_client=$from"); mysql_query("SET character_set_results=$to"); $string_escaped = mysql_real_escape_string($string); $converted_string = mysql_result(mysql_query("SELECT '$string_escaped'"),0,0); // restore previous character set values: mysql_query("SET character_set_client=$character_set_database"); mysql_query("SET character_set_results=$character_set_results"); return $converted_string; } ?>

« previous php.notes (#131763) next »