Results 1 to 6 of 6
-
16th Jun 2009, 12:22 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comTake 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>
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);
}
?>
....
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>
- Compressed
- Harder to read
- 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: 5Join 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
-
16th Jun 2009, 12:32 PM #2MemberWebsite's:
WareztheDDL.com GTFO.wsit 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
-
16th Jun 2009, 12:40 PM #3The Wise OneWebsite's:
twilight.ws ddlrank.comLitewarez 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
-
16th Jun 2009, 12:43 PM #4OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comthis 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>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
-
16th Jun 2009, 12:46 PM #5OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comthe 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
-
16th Jun 2009, 10:20 PM #6Banned
Thanks for this, very handy
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
The advantage to use a VPS ?
By vido in forum Webmasters, Money MakingReplies: 3Last Post: 7th Oct 2011, 08:47 PM -
Advantage of Z-O-O-M Uploder tool?
By neel in forum General DiscussionReplies: 20Last Post: 5th Sep 2011, 05:50 PM -
sborg advantage
By mohsingr8 in forum Webmaster DiscussionReplies: 7Last Post: 13th Jan 2011, 01:23 PM -
Do u take advantage of the Newsletter function?
By Clowner in forum Webmaster DiscussionReplies: 3Last Post: 6th Dec 2010, 09:18 AM -
Whats the advantage of RS ?
By Th3Kill33r in forum File Host DiscussionReplies: 20Last Post: 10th Nov 2010, 06:48 AM
themaCreator - create posts from...
Version 3.21 released. Open older version (or...