Welcome Guest, Not a member yet? Register   Sign In
Do you want to clean your code?, try this
#1

[eluser]amrnt[/eluser]
if you want to get a clean and clear output of you code, try to do this:

in your system/index.php, write in the top of this page:
Code:
ob_start();

and at the bottom of it write:
Code:
$string=ob_get_contents();// get the output code
ob_get_clean();
$string = str_replace("\n", '', $string);// remove \n
$string = str_replace("\r", '', $string);// remove \r
$string = str_replace("  ", '', $string);// dont replace a single space with nothing -> it gets you no spaces between codes. error example:<imgsrc=""/>
$string = str_replace("\t", '', $string);// remove \t
$string = preg_replace('/[ ]+/', '', $string);// remove between // like /*blablabla*/
$string = preg_replace('/&lt;!--[^-]*--&gt;/', '', $string);// remove comments
ob_start('gzip');
echo($string);// get the clean code

hope to be useful and clear Wink
#2

[eluser]Yash[/eluser]
looks handy to me.Thanx
#3

[eluser]Référencement Google[/eluser]
You should have told "Make your code unreadable" instead of saying cleaning it.
#4

[eluser]amrnt[/eluser]
[quote author="Too Pixel" date="1218246511"]You should have told "Make your code unreadable" instead of saying cleaning it.[/quote]

maybe, but for me i use it for cleaning ... thanks for commenting
i comment \n and \r to get clean,
#5

[eluser]Référencement Google[/eluser]
I don't understand really, for your having things like <imgsrc=""/> without any space and code without tabs, line returns means "clean" ? What's the goal doing such things?
#6

[eluser]amrnt[/eluser]
[quote author="Too Pixel" date="1218251452"]I don't understand really, for your having things like <imgsrc=""/> without any space and code without tabs, line returns means "clean" ? What's the goal doing such things?[/quote]

I said if we clean each space we will have errors.
img tag :
Code:
<img src="">
if we clean each space we will get <imgsrc=""/> and this gets us nothing..
that means NOT TO REPLACE a single space with nothing ,so i replaced 2 spaces with nothing !!

Code:
$string = str_replace("  ", '', $string);// dont replace a single space with nothing -> it gets you no spaces between codes. error example:<imgsrc=""/>

hope you got it !
#7

[eluser]nmweb[/eluser]
It saves you a few bytes of traffic whilst giving php a lot of extra stuff to do. If you want to optimize, gzip your output but please don't bother about a couple of bytes of spaces and new lines. It's bad for performance and readability.

It is covered in this topic: http://ellislab.com/forums/viewthread/65658/P15/ the results speak for themselves
Quote:no gzip no strip : 33 kb 47ms
gzip no strip : 7 kb 31 ms
no gzip strip (new code) : 31 kb 31 ms
gzip strip (new code) : 6 kb 63 ms
#8

[eluser]Référencement Google[/eluser]
Yes amrtami I got it but still thinking it's not a good thing to do.
With CI you can activate in the config.php file the Gzip page compression, that's enough. If you are really looking for performances, then a caching solution seems better than saving small bytes.
#9

[eluser]amrnt[/eluser]
[quote author="Too Pixel" date="1218252975"]then a caching solution seems better than saving small bytes.[/quote]

of course, I'm with you with that.

when i enabled Gzip, page didnt load and give me
Code:
Fatal error: ob_start() [<a href='ref.outcontrol'>ref.outcontrol</a>]: Cannot use output buffering in output buffering display handlers in E:\projects\webs\ci\system\libraries\Exceptions.php on line 160
#10

[eluser]Référencement Google[/eluser]
I think you are echoing something before sending to output. Look into the config comments:

Quote:| VERY IMPORTANT: If you are getting a blank page when compression is enabled it
| means you are prematurely outputting something to your browser. It could
| even be a line of whitespace at the end of one of your scripts. For
| compression to work, nothing can be sent before the output buffer is called
| by the output class. Do not "echo" any values with compression enabled.




Theme © iAndrew 2016 - Forum software by © MyBB