note 71644 added to ref.iconv

From: Date: Sat, 09 Dec 2006 23:05:02 +0000
Subject: note 71644 added to ref.iconv
Groups: php.notes 
Request: Send a blank email to php-notes+get-120461@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 192.117.122.43 Probable Submitter: 217.132.119.78 ---- Manual Page -- http://www.php.net/manual/en/ref.iconv.php Edit -- https://master.php.net/note/edit/71644 Del: integrated -- https://master.php.net/note/delete/71644/integrated Del: useless -- https://master.php.net/note/delete/71644/useless Del: bad code -- https://master.php.net/note/delete/71644/bad+code Del: spam -- https://master.php.net/note/delete/71644/spam Del: non-english -- https://master.php.net/note/delete/71644/non-english Del: in docs -- https://master.php.net/note/delete/71644/in+docs Del: other reasons-- https://master.php.net/note/delete/71644 Reject -- https://master.php.net/note/reject/71644 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120461) next »