Activity Stream
48,167 MEMBERS
62440 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 6 of 6
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default Take full advantage of ob_start(); ... Magic

    ok today i will be talking about ob_start() and how to take advantage of it in a different way than most people

    here is a normal usage of ob_start()

    PHP Code: 
    <?php
    ob_start
    ();
    ?>
    <html>
    <head>
    <title>Ob start Basic Example</title>
    </head>
    <body>

    <div><p>Here is just a paragraph just to act as a content filler</p></div>

    </body>
    </html>
    Now when you run ob_start it will run threw a process of compressing your data before sending it to the web browser.

    what where going to do is create our own process for it to run so we then can change the way the data is sent to the browsers.

    ok so firstly we need to create a function that will take the data in then process it and then send it t the browser

    PHP Code: 
    $EnableGZipEncoding true// if this is true, will return the html gZip'ed

    function gZipAllowed(){ //this is a check to see if the browser can accept gZip
        
    $accept str_replace(" ","",strtolower($_SERVER['HTTP_ACCEPT_ENCODING']));
        
    $accept explode(",",$accept);
        return 
    in_array("gzip",$accept);
    }

    function 
    cleanHtml($OutputHtml){
        
    now inside this function we can do many things from trimming to removing newlines and carriage returns
        
    $html preg_replace("/\s+/"," ",$OutputHtml);//shrinking spaces
        
    $html preg_replace("/\r+/"," ",$OutputHtml);//shrinking returns
        
    $html preg_replace("/\n+/"," ",$OutputHtml);//shrinking new lines
        
    return $html;
    }

    function 
    LitewarezObHandler($OutputHtml){
        global 
    $EnableGZipEncoding;
       
        
    $OutputHtml cleanHtml($OutputHtml);
        
        if(! 
    gZipAllowed() || headers_sent() || !$EnableGZipEncoding) return $OutputHtml;

        
    header("Content-Encoding: gzip");
        return 
    gzencode($OutputHtml);
    }
    ?> 
    Now in the LitewarezObHandler() function can do whatever we want to the html so you can create a mini templating system if you wish by replacing {home_link} in the function

    ....

    so now the usage of this fantastic html controller..

    PHP Code: 
    <?php
    //make sure that the functions above are included here
    ob_start('LitewarezObHandler');

    //so what we are doing here is telling ob_start to pass the html data threw my special function
    ?>
    <html>
    <head>
    <title>Ob start Basic Example</title>
    </head>
    <body>

    <div><p>Here is just a paragraph just to act as a content filler</p></div>

    </body>
    </html>

    heres what a user will see if he looks at your source
    PHP Code: 
    <html><head><title>Ob start Basic Example</title></head><body><div><p>Here is just a paragraph just to act as a content filler</p></div></body></html
    Now all your source code will be
    1. Compressed
    2. Harder to read
    3. works with 90% of browsers
    litewarez Reviewed by litewarez on . Take full advantage of ob_start(); ... Magic ok today i will be talking about ob_start() and how to take advantage of it in a different way than most people here is a normal usage of ob_start() <?php ob_start(); ?> <html> <head> Rating: 5
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    WareztheDDL.com GTFO.ws
    it will make your source 1 line?
    PHP does a lot of these things that arent really needed though. Like for example. when would this be "needed"?
    but fasting loading times and less bandwidth is always a good thing


  4.     
    #3
    The Wise One
    Website's:
    twilight.ws ddlrank.com
    Litewarez that's the reason why I can't open your site because it is saying you use a invallid or unsupported method of compression. Just thought you should know.
    I can always be contacted by sending a tweet @twilightws

  5.     
    #4
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    this is not just for making your source for one line you can do stuff like

    PHP Code: 
    <?php ob_start('LitewarezObHandler')?>
    <body>
    <div id="header">{_HEADER_}</div>
    <div id="leftbar">{_LEFTMU_}</div>
    <div id="main-content">{_CONTENT_}</div>
    <div id="footer">{_FOOTER_}</div>
    </body>
    and in the LitewarezObHandler you can repplacewhats in the brackets with content from DB/FILE w/e
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  6.     
    #5
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    the problem is the bloke who im running it with is grounded like a lil kid so i dont have root access and the hard drive is full meaning all things are down from SESSIONS , MYSQL , and the the fact that my settings for compression are used throughout sessions and come fromt he database the server is running under the wrong encodeing..... all this for a lil hard drive space has driven me mad lol
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  7.     
    #6
    Banned
    Thanks for this, very handy

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. The advantage to use a VPS ?
    By vido in forum Webmasters, Money Making
    Replies: 3
    Last Post: 7th Oct 2011, 08:47 PM
  2. Advantage of Z-O-O-M Uploder tool?
    By neel in forum General Discussion
    Replies: 20
    Last Post: 5th Sep 2011, 05:50 PM
  3. sborg advantage
    By mohsingr8 in forum Webmaster Discussion
    Replies: 7
    Last Post: 13th Jan 2011, 01:23 PM
  4. Do u take advantage of the Newsletter function?
    By Clowner in forum Webmaster Discussion
    Replies: 3
    Last Post: 6th Dec 2010, 09:18 AM
  5. Whats the advantage of RS ?
    By Th3Kill33r in forum File Host Discussion
    Replies: 20
    Last Post: 10th Nov 2010, 06:48 AM

Tags for this Thread

BE SOCIAL