Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post

    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??

  • #2
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    is it too hard to figure it out !! please share yout idea what ever it was. it will be apreciated.

  • #3
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •