note 40598 deleted from ref.iconv by nlopess
| From: | nlopess@php.net | Date: | Tue, 09 Mar 2004 14:59:44 +0000 |
| Subject: | note 40598 deleted from ref.iconv by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66501@lists.php.net to get a copy of this message | ||
Note Submitter: MagicalTux at FF.ST
----
If you forgot to compile iconv in PHP but you want to use the function iconv() and you have the
iconv binary accessible to the web server, you can use this little function :
<?
if (!function_exists('iconv')) {
function iconv($src,$dst,$str) {
$str=str_replace('END','E-ND',$str); // make sure we're not
stopped
$str.="\nEND";
$prog=popen('/usr/bin/iconv -f '.escapeshellarg($src).' -t
'.escapeshellarg($dst)." << END\n".$str,'r');
$res='';
while(!feof($prog)) $res.=fread($prog,4096);
pclose($prog);
$res=str_replace('E-ND','END',$res);
$res=substr($res,0,strlen($res)-1); // remove the \n we added
return $res;
}
}
?>
If your hosting company allows you to use popen and gave you shell access, you can even compile a
static build of the iconv binary and upload it to your FTP, then update the popen parameter in order
to reflect to your configuration. Remember that popen requires /bin/sh to exist !