...

View Full Version : help with utf-8 BOM's and smarty



skmd
07-08-2008, 01:51 PM
hi everyone,

i'm new to smarty templates and its really nice, but one thing i need to add.
i need to add this function to eliminate BOM's from templates before start compiling .


function removeBOM($str=""){
if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
$str=substr($str, 3);
}
return $str;
}
I suppose it must be somewhere in "fetch()" but I cant figure exactly where to put this function to work properly. can anyone help me with that??

skmd
07-09-2008, 03:16 PM
is it too hard to figure it out !! please share yout idea what ever it was. it will be apreciated.

kbluhm
07-09-2008, 04:18 PM
I am looking at Smarty v2.6.19 (most recent version).

Open Smarty.class.php and scroll to the method _read_file() on line 1707:


/**
* read in a file
*
* @param string $filename
* @return string
*/
function _read_file($filename)
{
if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) {
$contents = '';
while (!feof($fd)) {
$contents .= fread($fd, 8192);
}
fclose($fd);
return $contents;
} else {
return false;
}
}


Replace it with this one:


/**
* read in a file
*
* @param string $filename
* @return string
*/
function _read_file($filename)
{
if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) {
$contents = '';
while (!feof($fd)) {
$contents .= fread($fd, 8192);
}
fclose($fd);
$contents = removeBOM( $contents ); // customization: remove byte-order marks
return $contents;
} else {
return false;
}
}


Untested, but it should do what you're looking to accomplish.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum