Shrink PHP code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danielrs1
Forum Commoner
Posts: 29
Joined: Wed Jun 24, 2009 5:30 pm

Shrink PHP code

Post by danielrs1 »

Yes, this is weird. I need to shrink some PHP code. Does anyone know a script that does this?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Shrink PHP code

Post by Ollie Saunders »

A quick google produced this. Use the verb minify or noun minification to search for other implementations if you wish.
danielrs1
Forum Commoner
Posts: 29
Joined: Wed Jun 24, 2009 5:30 pm

Re: Shrink PHP code

Post by danielrs1 »

thanks. I can find lot's of tool for js, css and html, but I couldn't find any for PHP.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Shrink PHP code

Post by Ollie Saunders »

Why do you need this?
danielrs1
Forum Commoner
Posts: 29
Joined: Wed Jun 24, 2009 5:30 pm

Re: Shrink PHP code

Post by danielrs1 »

I've made a PHP app for a contest that has a 100KB limit. My app is slight bigger, so I need to make it smaller
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Shrink PHP code

Post by jackpf »

Try removing all the tabs and new lines. Comments too.

You could base64 encode it and eval it on execution. That should compress it a bit...
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Shrink PHP code

Post by Ollie Saunders »

You could:
  • Refactor; there's probably duplicated code you can remove. The shear number of refactors that are possible virtually guarantee this will be useful unless your code is already very well factored, which almost nobody's is.
  • Remove some unnecessary features; at least one is present in nearly every project, sometimes there are many.
  • Change to tab indentation if you were using spaces.
  • As jackpf suggested, removing unnecessary comments it also good. A lot of people repeat the license in every file for instance.
danielrs1
Forum Commoner
Posts: 29
Joined: Wed Jun 24, 2009 5:30 pm

Re: Shrink PHP code

Post by danielrs1 »

I have already done what you suggested, but thanks anyway.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Shrink PHP code

Post by John Cartwright »

jackpf wrote:Try removing all the tabs and new lines. Comments too.

You could base64 encode it and eval it on execution. That should compress it a bit...
The Manual wrote:Base64-encoded data takes about 33% more space than the original data.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Shrink PHP code

Post by jackpf »

Oh right. My bad.
Post Reply