FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Is there anything can make my PHP codes slim?





Mgccl
My php code is large... because there are sooo many spaces and well fomated

I want have another version on my server, which take out all unnessery spaces and comments...
Anything can do that or I must do it by hand?
raver
I don't understand why you would like to do that. Clean code is better alot of chunks put together... it will help you later when you will have to make modifications to it. But if you really want to, remove all of the spaces (by hand, i don't know another method) and you can try rewriting your code, for example using the ternary operator instead of if-else statements or switch instead of multiple if-elseif-else.
Hope this helps Cool
Enderwiggin
Ctrl + h in notepad, set the find to " " and the replace to "", that will remove every space if you hit remove all, but it will also work if you hit find next or replace manually...
Mgccl
There should be somekind of software to do that for you right>?
if just replace all spaces, you don't know which of them are useless ones which aren't
Rhysige
Trust me the speed increase for that would be tiny and for the difficulty it would not be worth it.
Mgccl
I need it just for smaller size, more compact script, sometimes the html codes inside PHP can be shortened, and use less bandwidth
Rhysige
Is your website pushing the bandwidth that much? or the space that small?
Mgccl
NO, I don't have that much bandwidth. But just want those PHP files be smaller, I think that will reduce the time on processing them
Nyizsa
Doing it you would not gain significant space, and the bandwidth would not be effected at all, because your script produces the same output. (And in case of PHP, only output is sent through.) It would not be parsed faster, because the parser removes spaces and remarks anyway. And I think you agree that we can assume that the original file and the file without spaces will need the same time to be read LOCALLY...
And you would lose your oversight on the script.
n0obie4life
Mgccl wrote:
NO, I don't have that much bandwidth. But just want those PHP files be smaller, I think that will reduce the time on processing them


There won't be much difference.

PHP doesn't process blank spaces. The blank spaces just make the code neater and easier to see.
BlackSkad
If your script really is to big, and you want to reduce it, you can try to divide the content over multiple files. This will, in most cases, also make your code more easy to read.

Maybe you can do it like this:
Code:
<?php
//some code

if( condition){
     //do something with
     //a lot of code....
}

Then take out the 'do something with a lot of code' and put it in a seperate file. Then include that file on the place where the code was:
Code:
<?php
//some code

if( condition){
     include ('the_codefile.php');
}


I hope this has helped you a little...
BlackSkad
Related topics
How To : Improve Your PHP Programming
Php and Other Wonderful Newbie Stories for Help.
I want PHP Online Games
PHP what is it actually?
Points Scripts
my PHP code benchmark script that got some problems
Help with php email
What do you use to make your page layout?
MACROMEDIA Dreamweaver
Phoenix free PHP scripts
membership management script
[SOLVED] PHP is not working
HowTO- Fireworks Web Document to be edit in Dreamweaver
Favourite Website Builder
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.