Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-08-2008, 12:51 PM   PM User | #1
skmd
New Coder

 
Join Date: Dec 2007
Posts: 96
Thanks: 8
Thanked 1 Time in 1 Post
skmd is an unknown quantity at this point
help with utf-8 BOM's and smarty

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 .
PHP Code:
function removeBOM($str=""){
        if(
substr($str0,3) == pack("CCC",0xef,0xbb,0xbf)) {
                
$str=substr($str3);
        }
        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 is offline   Reply With Quote
Old 07-09-2008, 02:16 PM   PM User | #2
skmd
New Coder

 
Join Date: Dec 2007
Posts: 96
Thanks: 8
Thanked 1 Time in 1 Post
skmd is an unknown quantity at this point
is it too hard to figure it out !! please share yout idea what ever it was. it will be apreciated.
skmd is offline   Reply With Quote
Old 07-09-2008, 03:18 PM   PM User | #3
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
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:
PHP Code:
    /**
     * 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($fd8192);
            }
            
fclose($fd);
            return 
$contents;
        } else {
            return 
false;
        }
    } 
Replace it with this one:
PHP Code:
    /**
     * 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($fd8192);
            }
            
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.
__________________
ZCE
kbluhm is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:21 PM.


Advertisement
Log in to turn off these ads.